home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / vir_real / veos / part10 < prev    next >
Encoding:
Internet Message Format  |  1993-06-20  |  72.3 KB

  1. Path: wupost!decwrl!decwrl!vixie!vixie!not-for-mail
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Newsgroups: comp.sources.unix
  4. Subject: v26i193: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part10/16
  5. Date: 25 Apr 1993 23:15:22 -0700
  6. Organization: Vixie Home Computing
  7. Lines: 2553
  8. Sender: vixie@vix.com
  9. Approved: paul@vix.com
  10. Message-ID: <1rfulq$5nv@efficacy.home.vix.com>
  11. NNTP-Posting-Host: efficacy.home.vix.com
  12.  
  13. Submitted-By: voodoo@hitl.washington.edu (Geoffery Coco)
  14. Posting-Number: Volume 26, Issue 193
  15. Archive-Name: veos-2.0/part10
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 10 (of 16)."
  24. # Contents:  src/kernel_current/shell/xv_native.c
  25. #   src/xlisp/xcore/c/xleval.c src/xlisp/xcore/c/xlftab.c
  26. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:42 1993
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'src/kernel_current/shell/xv_native.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'src/kernel_current/shell/xv_native.c'\"
  30. else
  31. echo shar: Extracting \"'src/kernel_current/shell/xv_native.c'\" \(24300 characters\)
  32. sed "s/^X//" >'src/kernel_current/shell/xv_native.c' <<'END_OF_FILE'
  33. X/****************************************************************************************
  34. X *                                            *
  35. X * file: xv_native.c                                    *
  36. X *                                            *
  37. X * the xlisp wrappers for the VEOS native prims.                    *
  38. X *                                            *
  39. X * creation: December, 1991                                *
  40. X *                                            *
  41. X *                                            *
  42. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  43. X *                                            *
  44. X ****************************************************************************************/
  45. X
  46. X
  47. X
  48. X/****************************************************************************************
  49. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  50. X ****************************************************************************************/
  51. X
  52. X
  53. X
  54. X/****************************************************************************************
  55. X                      Preliminaries
  56. X ****************************************************************************************/
  57. X
  58. X#include <math.h>
  59. X#include "xlisp.h"
  60. X
  61. X/* VEOS definitions: */
  62. X#include "kernel.h"
  63. X
  64. X#define DEFINE_NATIVE_GLOBS
  65. X#include "xv_native.h"
  66. X#undef DEFINE_NATIVE_GLOBS
  67. X
  68. X/****************************************************************************************/
  69. X
  70. XTVeosErr Native_MessageToLSpace();
  71. Xvoid Native_ShowMatchArgs();
  72. Xvoid Native_ShowSite();
  73. XTVeosErr Native_XCopySiteMatches();
  74. XTVeosErr Native_XRemoveSiteMatches();
  75. XTVeosErr Native_XInsertEltAtSite();
  76. Xvoid Native_NextMsg();
  77. XTVeosErr Native_DoThrow();
  78. X
  79. X/****************************************************************************************/
  80. X
  81. X
  82. X
  83. X/****************************************************************************************
  84. X                 Veos Primitive Wrappers
  85. X ****************************************************************************************/
  86. X
  87. X
  88. X/****************************************************************************************/
  89. XLVAL Native_Init()
  90. X{    
  91. X    LVAL         pXReturn;
  92. X    int        iPort;
  93. X    TVeosErr    iErr;
  94. X    
  95. X    xlsave1(pXReturn);
  96. X
  97. X    if (!moreargs())
  98. X    iPort = TALK_BOGUS_FD;
  99. X    else
  100. X    iPort = getfixnum(xlgafixnum());
  101. X
  102. X    xllastarg();
  103. X
  104. X
  105. X    /** invoke veos kernel inialization **/
  106. X    
  107. X    iErr = Kernel_Init(iPort, Native_MessageToLSpace);
  108. X    if (iErr == VEOS_SUCCESS) {
  109. X
  110. X
  111. X    /** create a lisp based inspace for messages **/
  112. X
  113. X    s_InSpace = xlenter("VEOS_INSPACE");
  114. X    setvalue(s_InSpace, NIL);
  115. X    NATIVE_INSPACE = &getvalue(s_InSpace);
  116. X
  117. X
  118. X    /** create keyword symbols for nancy prims **/
  119. X
  120. X    k_TestTime = xlenter(":TEST-TIME"); /* use with copy only */
  121. X    k_Freq = xlenter(":FREQ");         /* use with copy, put or get */
  122. X
  123. X
  124. X    /** setup invariant matcher settings in global param blocks **/
  125. X
  126. X    Native_InitMatcherPBs();
  127. X
  128. X
  129. X    /** make a uid return value to signify success **/
  130. X
  131. X
  132. X    Uid2XVect(&IDENT_ADDR, &pXReturn);
  133. X    }
  134. X
  135. X
  136. X    xlpop();
  137. X
  138. X
  139. X    return(pXReturn);
  140. X
  141. X    }  /* Native_Init */
  142. X/****************************************************************************************/
  143. X
  144. X
  145. X
  146. X/****************************************************************************************/
  147. XLVAL Native_Close()
  148. X{    
  149. X    if (!KERNEL_INIT)
  150. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  151. X
  152. X    xllastarg();
  153. X
  154. X    Kernel_Shutdown();
  155. X
  156. X    return(true);
  157. X
  158. X    } /* Native_Close */
  159. X/****************************************************************************************/
  160. X
  161. X
  162. X
  163. X/****************************************************************************************/
  164. XLVAL Native_Task()
  165. X{    
  166. X#ifndef OPTIMAL
  167. X    if (!KERNEL_INIT)
  168. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  169. X
  170. X    xllastarg();
  171. X#endif
  172. X
  173. X    /** talk will call our message handler and stuff the inspace **/
  174. X
  175. X    Kernel_SystemTask();
  176. X
  177. X
  178. X    return(true);
  179. X
  180. X    } /* Native_Task */
  181. X/****************************************************************************************/
  182. X
  183. X
  184. X
  185. X
  186. X/****************************************************************************************/
  187. XLVAL Native_Put()
  188. X{
  189. X    TVeosErr    iErr;
  190. X    TTimeStamp    tNow;
  191. X
  192. X#ifndef OPTIMAL
  193. X    if (!KERNEL_INIT)
  194. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  195. X#endif
  196. X
  197. X
  198. X
  199. X    /** get mandatory data argument **/
  200. X
  201. X    native_putPB.pXReplaceElt = xlgetarg();
  202. X
  203. X    
  204. X    
  205. X    /** get pattern from xlisp args **/
  206. X
  207. X    iErr = Native_GetPatternArg(&native_putPB.pPatGr, NANCY_ReplaceMatch);
  208. X    if (iErr != VEOS_SUCCESS)
  209. X    Native_TrapErr(iErr, nil);
  210. X
  211. X
  212. X    /** get optional frequency argument **/
  213. X
  214. X    NATIVE_FREQ_ARG(native_putPB.iFreqFlag);
  215. X
  216. X
  217. X    /** set the data time-stamp **/
  218. X
  219. X    GET_TIME(tNow);
  220. X    native_putPB.pStampTime = &tNow;
  221. X
  222. X
  223. X    /** dispatch the matcher **/
  224. X
  225. X    xlsave1(native_putPB.pXResult);
  226. X    
  227. X    Native_XMandR(&native_putPB);
  228. X
  229. X    xlpop();
  230. X
  231. X
  232. X
  233. X    /** clean up **/
  234. X
  235. X    Nancy_DisposeGrouple(native_putPB.pPatGr);
  236. X
  237. X
  238. X
  239. X    return (native_putPB.pXResult);
  240. X
  241. X    } /* Native_Put */
  242. X/****************************************************************************************/
  243. X
  244. X
  245. X/****************************************************************************************/
  246. XLVAL Native_Get()
  247. X{
  248. X    TVeosErr    iErr;
  249. X
  250. X#ifndef OPTIMAL
  251. X    if (!KERNEL_INIT)
  252. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  253. X#endif
  254. X
  255. X    /** get pattern from xlisp args **/
  256. X
  257. X    iErr = Native_GetPatternArg(&native_getPB.pPatGr, NANCY_RemoveMatch);
  258. X    if (iErr != VEOS_SUCCESS)
  259. X    Native_TrapErr(iErr, nil);
  260. X
  261. X
  262. X    /** get optional frequency argument **/
  263. X
  264. X    NATIVE_FREQ_ARG(native_getPB.iFreqFlag);
  265. X
  266. X
  267. X    /** dispatch the matcher **/
  268. X    
  269. X    xlsave1(native_getPB.pXResult);
  270. X
  271. X    Native_XMandR(&native_getPB);
  272. X
  273. X    xlpop();
  274. X
  275. X
  276. X    /** clean up **/
  277. X
  278. X    Nancy_DisposeGrouple(native_getPB.pPatGr);
  279. X
  280. X
  281. X
  282. X    return (native_getPB.pXResult);
  283. X
  284. X    } /* Native_Get */
  285. X/****************************************************************************************/
  286. X
  287. X
  288. X/****************************************************************************************/
  289. XLVAL Native_Copy()
  290. X{
  291. X    TVeosErr    iErr;
  292. X    TTimeStamp    tTest;
  293. X
  294. X#ifndef OPTIMAL
  295. X    if (!KERNEL_INIT)
  296. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  297. X#endif
  298. X
  299. X
  300. X
  301. X    /** get pattern from xlisp args **/
  302. X
  303. X    iErr = Native_GetPatternArg(&native_copyPB.pPatGr, NANCY_CopyMatch);
  304. X    if (iErr != VEOS_SUCCESS)
  305. X    Native_TrapErr(iErr, nil);
  306. X
  307. X
  308. X    /** look for optional time-stamp-test **/
  309. X
  310. X    NATIVE_TIME_ARG(native_copyPB.pTestTime, tTest);
  311. X
  312. X
  313. X    /** get optional frequency argument **/
  314. X
  315. X    NATIVE_FREQ_ARG(native_copyPB.iFreqFlag);
  316. X
  317. X
  318. X    /** dispatch the matcher **/
  319. X
  320. X    xlsave1(native_copyPB.pXResult);
  321. X    
  322. X    Native_XMandR(&native_copyPB);
  323. X
  324. X    xlpop();
  325. X
  326. X
  327. X    /** clean up **/
  328. X
  329. X    Nancy_DisposeGrouple(native_copyPB.pPatGr);
  330. X
  331. X
  332. X
  333. X    return (native_copyPB.pXResult);
  334. X
  335. X    } /* Native_Copy */
  336. X/****************************************************************************************/
  337. X
  338. X
  339. X/****************************************************************************************/
  340. XLVAL Native_Throw()
  341. X{
  342. X    LVAL    pXData, pXDests;
  343. X    TVeosErr    iErr;
  344. X
  345. X#ifndef OPTIMAL
  346. X    if (!KERNEL_INIT)
  347. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  348. X#endif
  349. X
  350. X    /** get dests argument **/
  351. X
  352. X    pXDests = xlgalist();
  353. X
  354. X
  355. X    /** get data argument **/
  356. X
  357. X    pXData = xlgetarg();
  358. X
  359. X#ifndef OPTIMAL
  360. X    xllastarg();
  361. X#endif
  362. X
  363. X    iErr = Native_DoThrow(pXDests, pXData);
  364. X
  365. X    return(iErr == VEOS_SUCCESS ? true : NIL);
  366. X
  367. X    } /* Native_Throw */
  368. X/****************************************************************************************/
  369. X
  370. X
  371. X
  372. X/****************************************************************************************/
  373. XLVAL Native_Catch()
  374. X{
  375. X    LVAL    pSave;
  376. X    TPElt    pElt;
  377. X
  378. X#ifndef OPTIMAL
  379. X    if (!KERNEL_INIT)
  380. X    Native_TrapErr(NATIVE_NOKERNEL, nil);
  381. X
  382. X    xllastarg();
  383. X#endif
  384. X
  385. X    Native_NextMsg(&pSave);
  386. X
  387. X    return (pSave);
  388. X
  389. X    } /* Native_Catch */
  390. X/****************************************************************************************/
  391. X
  392. X
  393. X
  394. X/****************************************************************************************/
  395. XLVAL Native_MinTime()
  396. X{    
  397. X    TF2L    fTrans;
  398. X    
  399. X    /* guaranteed to be earlier than any system time */
  400. X
  401. X    fTrans.u.l = NANCY_MINTIME;
  402. X
  403. X    return(cvflonum(fTrans.u.f));
  404. X
  405. X    }  /* Native_MinTime */
  406. X/****************************************************************************************/
  407. X
  408. X
  409. X
  410. X/****************************************************************************************/
  411. XLVAL Native_NoSignals()
  412. X{    
  413. X    SIG_ENABLE = FALSE;
  414. X
  415. X    return(true);
  416. X
  417. X    }  /* Native_NoSignals */
  418. X/****************************************************************************************/
  419. X
  420. X
  421. X
  422. X/****************************************************************************************/
  423. XLVAL Native_Bugs()
  424. X{    
  425. X    LVAL    pXModule;
  426. X    char    *sName;
  427. X
  428. X    pXModule = xlgastring();
  429. X    sName = (char *) getstring(pXModule);
  430. X    
  431. X    if (strcmp(sName, "talk") == 0)
  432. X    TALK_BUGS = TALK_BUGS ? FALSE : TRUE;
  433. X
  434. X    else if (strcmp(sName, "nancy") == 0)
  435. X    NANCY_BUGS = NANCY_BUGS ? FALSE : TRUE;
  436. X
  437. X    else if (strcmp(sName, "shell") == 0)
  438. X    SHELL_BUGS = SHELL_BUGS ? FALSE : TRUE;
  439. X
  440. X    return(true);
  441. X
  442. X    }  /* Native_Bugs */
  443. X/****************************************************************************************/
  444. X
  445. Xextern int iEvals;
  446. X
  447. X/****************************************************************************************/
  448. XLVAL Native_Zoot()
  449. X{
  450. X    static int    iAlreadySeen = 0;
  451. X    int        iSinceLast;
  452. X
  453. X    iSinceLast = iEvals - iAlreadySeen;
  454. X    iAlreadySeen = iEvals;
  455. X
  456. X    return(cvfixnum(iSinceLast));
  457. X
  458. X    } /* Native_Zoot */
  459. X/****************************************************************************************/
  460. X
  461. X
  462. X
  463. X
  464. X/****************************************************************************************
  465. X             The Beuractratic Linkage Between Veos and XLISP
  466. X ****************************************************************************************/
  467. X
  468. X
  469. X/****************************************************************************************/
  470. XTVeosErr Shell_LoadNativePrims()
  471. X{
  472. X#define VEOS_NATIVE_LOAD
  473. X#include "xv_native_prims.h"
  474. X#undef VEOS_NATIVE_LOAD
  475. X
  476. X    return(VEOS_SUCCESS);
  477. X    }
  478. X/****************************************************************************************/
  479. X
  480. X
  481. X/****************************************************************************************/
  482. XTVeosErr Shell_BailOut(sErr)
  483. X    char        *sErr;
  484. X{
  485. X
  486. X    xlfatal(sErr);
  487. X
  488. X    /** not reached **/
  489. X
  490. X    return(VEOS_SUCCESS);
  491. X
  492. X    } /* Shell_BailOut */
  493. X/****************************************************************************************/
  494. X
  495. X
  496. X
  497. X/****************************************************************************************
  498. X             The Sticky Goo Just Beneath the Wrappers
  499. X ****************************************************************************************/
  500. X
  501. X
  502. X/****************************************************************************************/
  503. XTVeosErr Native_InitMatcherPBs()
  504. X{
  505. X    /** vget settings **/
  506. X    
  507. X    native_getPB.pSrcGr = WORK_SPACE;
  508. X    native_getPB.iDestroyFlag = NANCY_RemoveMatch;
  509. X    native_getPB.pXReplaceElt = nil;
  510. X    native_getPB.pStampTime = nil;
  511. X    native_getPB.pTestTime = nil;
  512. X    
  513. X    /** vcopy settings **/
  514. X    
  515. X    native_copyPB.pSrcGr = WORK_SPACE;
  516. X    native_copyPB.iDestroyFlag = NANCY_CopyMatch;
  517. X    native_copyPB.pXReplaceElt = nil;
  518. X    native_copyPB.pStampTime = nil;
  519. X
  520. X    /** vput settings **/
  521. X    
  522. X    native_putPB.pSrcGr = WORK_SPACE;
  523. X    native_putPB.iDestroyFlag = NANCY_ReplaceMatch;
  524. X    native_putPB.pTestTime = nil;
  525. X
  526. X
  527. X    return(VEOS_SUCCESS);
  528. X    
  529. X    } /* Native_InitMatcherPBs */
  530. X/****************************************************************************************/
  531. X
  532. X
  533. X
  534. X/****************************************************************************************/
  535. XTVeosErr Native_DoThrow(pXDests, pXData)
  536. X    LVAL    pXData, pXDests;
  537. X{
  538. X    TPUidNode    pDests;
  539. X    TVeosErr    iErr;
  540. X    TMsgRec    msgOut;
  541. X
  542. X
  543. X    /** convert host/port vectors to talk uids **/
  544. X
  545. X    iErr = Native_XVectsToUids(pXDests, &pDests);
  546. X    if (iErr != VEOS_SUCCESS) {
  547. X    Native_TrapErr(iErr, pXDests);
  548. X    }
  549. X
  550. X    /** convert data element to flat network format **/
  551. X
  552. X    iErr = Native_XEltToMsgRec(pXData, &msgOut);
  553. X    if (iErr != VEOS_SUCCESS) {
  554. X    Native_DisposeUids(pDests);
  555. X    Native_TrapErr(iErr, pXData);
  556. X    }
  557. X
  558. X    /** pass the flat message to veos kernel **/
  559. X
  560. X    iErr = Talk_SpeakToMany(pDests, &msgOut);
  561. X
  562. X
  563. X    Native_DisposeUids(pDests);
  564. X
  565. X    return(iErr);
  566. X
  567. X    } /* Native_DoThrow */
  568. X/****************************************************************************************/
  569. X
  570. X
  571. X
  572. X/****************************************************************************************/
  573. Xvoid Native_NextMsg(hMsg)
  574. X    LVAL          *hMsg;
  575. X{
  576. X    *hMsg = NIL;
  577. X
  578. X    if (!null(*NATIVE_INSPACE)) {
  579. X    
  580. X    /** get the oldest message **/
  581. X    
  582. X    *hMsg = car(*NATIVE_INSPACE);
  583. X    
  584. X    /** remove this msg from list immediately. 
  585. X     ** first cons cell in this list will thus be garbage collected. 
  586. X     ** pass back the new msg. 
  587. X     **/ 
  588. X    
  589. X    *NATIVE_INSPACE = cdr(*NATIVE_INSPACE); 
  590. X    }
  591. X    }
  592. X/****************************************************************************************/
  593. X
  594. X
  595. X
  596. X/****************************************************************************************/
  597. XTVeosErr Native_XMandR(pMandRPB)
  598. X    TPXMandRRec        pMandRPB;
  599. X{
  600. X    TVeosErr        iErr;
  601. X    TMatchRec        matchSpec;
  602. X    TPReplaceRec    pSite, pSave;
  603. X
  604. X    
  605. X    /** Initialize the match record.
  606. X     ** This record get passed through the entire match process.
  607. X     ** The matcher uses to record sites for removal and insertion.
  608. X     ** If the matcher returns success,
  609. X     ** we then perform any destructive operations on the gspace.
  610. X     **/
  611. X
  612. X    matchSpec.pPatGr = pMandRPB->pPatGr;
  613. X    matchSpec.pSrcGr = pMandRPB->pSrcGr;
  614. X    matchSpec.iDestroyFlag = pMandRPB->iDestroyFlag;
  615. X    matchSpec.iFreqFlag = pMandRPB->iFreqFlag;
  616. X    matchSpec.pReplaceList = nil;
  617. X    matchSpec.pTouchList = nil;
  618. X
  619. X#ifndef OPTIMAL
  620. X    if (NANCY_BUGS) 
  621. X    Native_ShowMatchArgs(pMandRPB);
  622. X#endif
  623. X
  624. X    /************************************/
  625. X
  626. X    iErr = Nancy_MatchGrouple(&matchSpec);
  627. X
  628. X    /************************************/
  629. X
  630. X#ifndef OPTIMAL
  631. X    if (NANCY_BUGS)
  632. X    fprintf(stderr, "nancy %s: match %s.\n", 
  633. X        WHOAMI, iErr == VEOS_SUCCESS ? "succeeded" : "failed");
  634. X#endif
  635. X        
  636. X    /** Perform any destructive operations on the gspace.
  637. X     ** These occur in on a per-site basis.
  638. X     ** A site is:
  639. X     **   an enclosing grouple,
  640. X     **   a set of element intervals,
  641. X     **   an element index at which to insert.
  642. X     ** Sites are generated by the matcher during matching.
  643. X     **/
  644. X
  645. X    /** perform destructive element retrieval
  646. X     **/
  647. X
  648. X    switch (pMandRPB->iDestroyFlag) {
  649. X
  650. X    case NANCY_CopyMatch:
  651. X    for (pSite = matchSpec.pReplaceList;
  652. X         pSite && iErr == VEOS_SUCCESS;
  653. X         pSite = pSite->pNext) {
  654. X#ifndef OPTIMAL
  655. X        if (NANCY_BUGS) 
  656. X        Native_ShowSite(pSite);
  657. X#endif
  658. X        iErr = Native_XCopySiteMatches(pSite, pMandRPB->pTestTime,
  659. X                       &pMandRPB->pXResult);
  660. X        }
  661. X    break;
  662. X        
  663. X    case NANCY_RemoveMatch:
  664. X    for (pSite = matchSpec.pReplaceList;
  665. X         pSite && iErr == VEOS_SUCCESS;
  666. X         pSite = pSite->pNext) {
  667. X
  668. X#ifndef OPTIMAL
  669. X        if (NANCY_BUGS) 
  670. X        Native_ShowSite(pSite);
  671. X#endif
  672. X        iErr = Native_XRemoveSiteMatches(pSite, pMandRPB->pTestTime,
  673. X                         &pMandRPB->pXResult);
  674. X        }
  675. X    break;
  676. X
  677. X    case NANCY_ReplaceMatch:
  678. X    for (pSite = matchSpec.pReplaceList;
  679. X         pSite && iErr == VEOS_SUCCESS;
  680. X         pSite = pSite->pNext) {
  681. X
  682. X#ifndef OPTIMAL
  683. X        if (NANCY_BUGS) 
  684. X        Native_ShowSite(pSite);
  685. X#endif
  686. X        iErr = Native_XRemoveSiteMatches(pSite, pMandRPB->pTestTime,
  687. X                         &pMandRPB->pXResult);
  688. X        if (iErr == VEOS_SUCCESS)
  689. X        iErr = Native_XInsertEltAtSite(pMandRPB->pXReplaceElt,
  690. X                           pMandRPB->pStampTime, pSite);
  691. X        }
  692. X    break;
  693. X        
  694. X    case NANCY_GimmeMatch:
  695. X    iErr = NANCY_NotSupported;
  696. X    break;
  697. X        
  698. X    } /* switch */
  699. X            
  700. X
  701. X    /** perform destructive element time stamping
  702. X     **/
  703. X
  704. X    if (pMandRPB->pStampTime) {
  705. X
  706. X    for (pSite = matchSpec.pTouchList;
  707. X         pSite && iErr == VEOS_SUCCESS;
  708. X         pSite = pSite->pNext) {
  709. X#ifndef OPTIMAL        
  710. X        if (NANCY_BUGS) 
  711. X        Native_ShowSite(pSite);
  712. X#endif        
  713. X        Native_TouchSiteMatches(pSite, *pMandRPB->pStampTime);
  714. X        
  715. X        }
  716. X    }
  717. X
  718. X    /** free all matcher memory (stays within veos kernel) **/
  719. X
  720. X    pSite = matchSpec.pReplaceList;
  721. X    while (pSite) {
  722. X    pSave = pSite;
  723. X    pSite = pSite->pNext;
  724. X    Shell_ReturnBlock(pSave, sizeof(TReplaceRec), "replace-bp");
  725. X    }
  726. X
  727. X    pSite = matchSpec.pTouchList;
  728. X    while (pSite) {
  729. X    pSave = pSite;
  730. X    pSite = pSite->pNext;
  731. X    Shell_ReturnBlock(pSave, sizeof(TReplaceRec), "replace-bp");
  732. X    }
  733. X    
  734. X
  735. X    if (iErr == VEOS_SUCCESS) {
  736. X
  737. X    /** check for successful insert (give caller appropriate feeback) **/
  738. X
  739. X    if (pMandRPB->iDestroyFlag == NANCY_ReplaceMatch &&
  740. X        pMandRPB->pXResult == NIL)
  741. X
  742. X        pMandRPB->pXResult = true;
  743. X    }
  744. X
  745. X#ifndef OPTIMAL
  746. X    else {
  747. X    if (NANCY_BUGS)
  748. X        Nancy_TrapErr(iErr);
  749. X    }
  750. X#endif
  751. X
  752. X    return(iErr);
  753. X
  754. X    } /* Native_MatchAndReplace */
  755. X/****************************************************************************************/
  756. X
  757. X    
  758. X
  759. X/****************************************************************************************/
  760. XTVeosErr Native_XCopySiteMatches(pSite, pTestTime, hXResult)
  761. X    TPReplaceRec    pSite;
  762. X    TPTimeStamp        pTestTime;
  763. X    LVAL        *hXResult;
  764. X{
  765. X    int            iZone, iToKill, iElt, iLeft, iRight;
  766. X    LVAL        pXElt;
  767. X    TPElt        pVElt;
  768. X    TVeosErr        iErr;
  769. X
  770. X    xlsave1(pXElt);
  771. X
  772. X    /** convert outgoing data into supplanted language format.
  773. X     ** lisp is the current control language
  774. X     **/
  775. X    
  776. X    if (pTestTime == nil) {
  777. X    
  778. X    for (iZone = pSite->iZones - 1; iZone >= 0; iZone --) {
  779. X        iLeft = pSite->pWipeList[iZone].iLeft;
  780. X        iRight = pSite->pWipeList[iZone].iRight;
  781. X        iToKill = iRight - iLeft + 1;
  782. X
  783. X#ifndef OPTIMAL        
  784. X        if (NANCY_BUGS) {
  785. X        fprintf(stderr, "nancy %s: left: %d right: %d\n",
  786. X            WHOAMI, iLeft, iRight);
  787. X        }
  788. X#endif        
  789. X        for (iElt = iRight, pVElt = &pSite->pEnviron->pEltList[iRight];
  790. X         iElt >= iLeft;
  791. X         iElt--, pVElt --) {
  792. X
  793. X        if (Native_VEltToXElt(pVElt, &pXElt) == VEOS_SUCCESS)
  794. X            
  795. X            /** assume caller protected *hXResult **/
  796. X            *hXResult = cons(pXElt, *hXResult);
  797. X        }
  798. X        }
  799. X    }
  800. X    else {
  801. X
  802. X    for (iZone = pSite->iZones - 1; iZone >= 0; iZone --) {
  803. X        iLeft = pSite->pWipeList[iZone].iLeft;
  804. X        iRight = pSite->pWipeList[iZone].iRight;
  805. X        iToKill = iRight - iLeft + 1;
  806. X
  807. X#ifndef OPTIMAL
  808. X        if (NANCY_BUGS) {
  809. X        fprintf(stderr, "nancy %s: left: %d right: %d\n",
  810. X            WHOAMI, iLeft, iRight);
  811. X        }
  812. X#endif    
  813. X
  814. X        for (iElt = iRight, pVElt = &pSite->pEnviron->pEltList[iRight];
  815. X         iElt >= iLeft;
  816. X         iElt--, pVElt--) {
  817. X        
  818. X        iErr = Native_NewVEltToXElt(pVElt, &pXElt, *pTestTime);
  819. X        if (iErr == VEOS_SUCCESS) {
  820. X
  821. X            /** assume caller protected *hXResult **/
  822. X            *hXResult = cons(pXElt, *hXResult);
  823. X            }
  824. X        /*
  825. X        else if (iErr == NATIVE_STALE)
  826. X            iErr = VEOS_SUCCESS;
  827. X            */
  828. X        }
  829. X        }
  830. X    }
  831. X
  832. X    xlpop();
  833. X
  834. X    return(VEOS_SUCCESS);
  835. X
  836. X    } /* Native_XCopySiteMatches */
  837. X/****************************************************************************************/
  838. X
  839. X
  840. X
  841. X/****************************************************************************************/
  842. XTVeosErr Native_XRemoveSiteMatches(pSite, pTestTime, hXResult)
  843. X    TPReplaceRec    pSite;
  844. X    TPTimeStamp        pTestTime;
  845. X    LVAL        *hXResult;
  846. X{
  847. X    int            iZone, iToKill, iElt, iLeft, iRight;
  848. X    LVAL        pXElt;
  849. X    TPElt        pVElt;
  850. X
  851. X    xlsave1(pXElt);
  852. X
  853. X    for (iZone = pSite->iZones - 1; iZone >= 0; iZone --) {
  854. X    iLeft = pSite->pWipeList[iZone].iLeft;
  855. X    iRight = pSite->pWipeList[iZone].iRight;
  856. X    iToKill = iRight - iLeft + 1;
  857. X    
  858. X    /** convert outgoing data into supplanted language format.
  859. X     ** that format is xlisp, and in reverse order
  860. X     **/
  861. X    
  862. X    for (iElt = iRight, pVElt = &pSite->pEnviron->pEltList[iRight];
  863. X         iElt >= iLeft;
  864. X         iElt--, pVElt--) {
  865. X
  866. X        if (Native_VEltToXElt(pVElt, &pXElt) == VEOS_SUCCESS)
  867. X
  868. X        /** assume caller has protected *hXResult **/
  869. X
  870. X        *hXResult = cons(pXElt, *hXResult);
  871. X        }
  872. X    
  873. X    Nancy_DeleteElementsInGrouple(pSite->pEnviron,
  874. X                      iLeft,
  875. X                      iToKill);
  876. X    }
  877. X
  878. X    xlpop();
  879. X
  880. X    return(VEOS_SUCCESS);
  881. X
  882. X    } /* Native_XRemoveSiteMatches */
  883. X/****************************************************************************************/
  884. X
  885. X
  886. X
  887. X/****************************************************************************************/
  888. XTVeosErr Native_XInsertEltAtSite(pXReplaceElt, pStampTime, pSite)
  889. X    LVAL        pXReplaceElt;
  890. X    TPTimeStamp        pStampTime;
  891. X    TPReplaceRec    pSite;
  892. X{
  893. X    TElt        localElt;
  894. X    TVeosErr        iErr = VEOS_SUCCESS;
  895. X
  896. X    if (pSite->iInsertElt >= 0) {
  897. X    
  898. X    localElt = NIL_ELT;
  899. X
  900. X    if (pStampTime)
  901. X        iErr = Native_XEltToNewVElt(pXReplaceElt, &localElt, *pStampTime);
  902. X    else
  903. X        iErr = Native_XEltToVElt(pXReplaceElt, &localElt);
  904. X
  905. X    if (iErr == VEOS_SUCCESS) {
  906. X
  907. X        Nancy_NewElementsInGrouple(pSite->pEnviron, pSite->iInsertElt, 1,
  908. X                       GR_unspecified, 0);
  909. X        pSite->pEnviron->pEltList[pSite->iInsertElt] = localElt;
  910. X        }
  911. X    }
  912. X
  913. X    return(iErr);
  914. X    
  915. X    } /* Native_XInsertEltAtSite */
  916. X/****************************************************************************************/
  917. X
  918. X
  919. X
  920. X/****************************************************************************************/
  921. XTVeosErr Native_TouchSiteMatches(pSite, time)
  922. X    TPReplaceRec    pSite;
  923. X    TTimeStamp        time;
  924. X{
  925. X    int            iZone, iElt, iLeft, iRight;
  926. X    TPElt        pVElt;
  927. X
  928. X    for (iZone = pSite->iZones - 1; iZone >= 0; iZone --) {
  929. X
  930. X    iLeft = pSite->pWipeList[iZone].iLeft;
  931. X    iRight = pSite->pWipeList[iZone].iRight;
  932. X    
  933. X    /** simply update time stamp of given elements **/
  934. X    
  935. X    for (iElt = iRight, pVElt = &pSite->pEnviron->pEltList[iRight];
  936. X         iElt >= iLeft; 
  937. X         iElt--, pVElt--)
  938. X
  939. X        pVElt->tLastMod = time;
  940. X    }
  941. X
  942. X    return(VEOS_SUCCESS);
  943. X
  944. X    } /* Native_TouchSiteMatches */
  945. X/****************************************************************************************/
  946. X
  947. X
  948. X
  949. X/****************************************************************************************/
  950. XTVeosErr Native_MessageToLSpace(pMsgRec)
  951. X    TPMsgRec        pMsgRec;
  952. X{
  953. X    TVeosErr         iErr;
  954. X    LVAL        pXElt, *hFinger;
  955. X    int            iLen;
  956. X    char        *pBuf;
  957. X
  958. X
  959. X    xlsave1(pXElt);
  960. X
  961. X    /** return data to grouple form **/            
  962. X    
  963. X    pBuf = pMsgRec->sMessage;
  964. X    iLen = 0;
  965. X    iErr = Native_MessageToXElt(pBuf, &pXElt, &iLen);
  966. X    
  967. X#ifndef OPTIMAL    
  968. X    if (TALK_BUGS) {
  969. X    fprintf(stderr, "listen %s: results of message conversion, native: %d\n",
  970. X        WHOAMI, iErr);
  971. X    }    
  972. X#endif
  973. X    
  974. X    if (iErr == VEOS_SUCCESS) {
  975. X
  976. X#ifndef OPTIMAL    
  977. X    if (TALK_BUGS) {
  978. X        fprintf(stderr, "listen %s: element in message:\n", WHOAMI);
  979. X
  980. X        errprint(pXElt);
  981. X        }
  982. X#endif
  983. X
  984. X    /** append message to native inspace list **/
  985. X    
  986. X    hFinger = NATIVE_INSPACE;
  987. X    while (!null(*hFinger))
  988. X        hFinger = &cdr(*hFinger);
  989. X
  990. X    *hFinger = cons(pXElt, NIL);
  991. X    }
  992. X
  993. X    xlpop();
  994. X
  995. X    return(iErr);
  996. X
  997. X    } /* Native_MessageToLSpace */
  998. X/****************************************************************************************/
  999. X
  1000. X
  1001. X
  1002. X/****************************************************************************************/
  1003. Xvoid Native_ShowMatchArgs(pMandRPB)
  1004. X    TPXMandRRec        pMandRPB;
  1005. X{
  1006. X    fprintf(stderr, "nancy %s: MandR arguments.\n", WHOAMI);
  1007. X
  1008. X    fprintf(stderr, "nancy %s: source:\n", WHOAMI);
  1009. X    Nancy_GroupleToStream(pMandRPB->pSrcGr, stderr);
  1010. X
  1011. X    fprintf(stderr, "nancy %s: pattern:\n", WHOAMI);
  1012. X    Nancy_GroupleToStream(pMandRPB->pPatGr, stderr);
  1013. X    
  1014. X    fprintf(stderr, "nancy %s: destroyFlag: %s\n", WHOAMI,
  1015. X        pMandRPB->iDestroyFlag == NANCY_RemoveMatch ? "remove" :
  1016. X        pMandRPB->iDestroyFlag == NANCY_CopyMatch ? "copy" :
  1017. X        pMandRPB->iDestroyFlag == NANCY_ReplaceMatch ? "replace" : "unknown");
  1018. X    
  1019. X    fprintf(stderr, "nancy %s: freqFlag: %s\n", WHOAMI,
  1020. X        pMandRPB->iFreqFlag == NANCY_MatchOne ? "one" : "all");
  1021. X    
  1022. X    fprintf(stderr, "nancy %s: replace elt:\n", WHOAMI);
  1023. X    errprint(pMandRPB->pXReplaceElt);
  1024. X    
  1025. X    fprintf(stderr, "nancy %s: stamp-time: ", WHOAMI);
  1026. X    if (pMandRPB->pStampTime)
  1027. X    PRINT_TIME(*pMandRPB->pStampTime, stderr);
  1028. X    else
  1029. X    fprintf(stderr, "nil");
  1030. X    fprintf(stderr, "\n");
  1031. X
  1032. X    fprintf(stderr, "nancy %s: test-time: ", WHOAMI);
  1033. X    if (pMandRPB->pTestTime)
  1034. X    PRINT_TIME(*pMandRPB->pTestTime, stderr);
  1035. X    else
  1036. X    fprintf(stderr, "nil");
  1037. X    fprintf(stderr, "\n");
  1038. X
  1039. X    } 
  1040. X/****************************************************************************************/
  1041. X
  1042. X
  1043. X
  1044. X/****************************************************************************************/
  1045. Xvoid Native_ShowSite(pSite)
  1046. X    TPReplaceRec           pSite;
  1047. X{
  1048. X    fprintf(stderr, "nancy %s: site grouple:\n", WHOAMI);
  1049. X    Nancy_GroupleToStream(pSite->pEnviron, stderr);
  1050. X    fprintf(stderr, "nancy %s: site zones: %d\n", WHOAMI, pSite->iZones);
  1051. X    fprintf(stderr, "nancy %s: site insert elt: %d\n", WHOAMI, pSite->iInsertElt);
  1052. X    }
  1053. X/****************************************************************************************/
  1054. X
  1055. X
  1056. X
  1057. END_OF_FILE
  1058. if test 24300 -ne `wc -c <'src/kernel_current/shell/xv_native.c'`; then
  1059.     echo shar: \"'src/kernel_current/shell/xv_native.c'\" unpacked with wrong size!
  1060. fi
  1061. # end of 'src/kernel_current/shell/xv_native.c'
  1062. fi
  1063. if test -f 'src/xlisp/xcore/c/xleval.c' -a "${1}" != "-c" ; then 
  1064.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xleval.c'\"
  1065. else
  1066. echo shar: Extracting \"'src/xlisp/xcore/c/xleval.c'\" \(21287 characters\)
  1067. sed "s/^X//" >'src/xlisp/xcore/c/xleval.c' <<'END_OF_FILE'
  1068. X/* -*-C-*-
  1069. X********************************************************************************
  1070. X*
  1071. X* File:         xleval.c
  1072. X* RCS:          $Header: xleval.c,v 1.3 89/11/25 05:21:43 mayer Exp $
  1073. X* Description:  xlisp evaluator
  1074. X* Author:       David Michael Betz
  1075. X* Created:      
  1076. X* Modified:     Sat Nov 25 05:21:14 1989 (Niels Mayer) mayer@hplnpm
  1077. X* Language:     C
  1078. X* Package:      N/A
  1079. X* Status:       X11r4 contrib tape release
  1080. X*
  1081. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  1082. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  1083. X*
  1084. X* Permission to use, copy, modify, distribute, and sell this software and its
  1085. X* documentation for any purpose is hereby granted without fee, provided that
  1086. X* the above copyright notice appear in all copies and that both that
  1087. X* copyright notice and this permission notice appear in supporting
  1088. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  1089. X* used in advertising or publicity pertaining to distribution of the software
  1090. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  1091. X* make no representations about the suitability of this software for any
  1092. X* purpose. It is provided "as is" without express or implied warranty.
  1093. X*
  1094. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  1095. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  1096. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  1097. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  1098. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  1099. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  1100. X* PERFORMANCE OF THIS SOFTWARE.
  1101. X*
  1102. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  1103. X* 
  1104. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  1105. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  1106. X*
  1107. X********************************************************************************
  1108. X*/
  1109. Xstatic char rcs_identity[] = "@(#)$Header: xleval.c,v 1.3 89/11/25 05:21:43 mayer Exp $";
  1110. X
  1111. X#include "xlisp.h"
  1112. X
  1113. X/* macro to check for lambda list keywords */
  1114. X#define iskey(s) ((s) == lk_optional \
  1115. X               || (s) == lk_rest \
  1116. X               || (s) == lk_key \
  1117. X               || (s) == lk_aux \
  1118. X               || (s) == lk_allow_other_keys)
  1119. X
  1120. X/* macros to handle tracing */
  1121. X#define trenter(sym,argc,argv) {if (sym) doenter(sym,argc,argv);}
  1122. X#define trexit(sym,val) {if (sym) doexit(sym,val);}
  1123. X
  1124. X/* external variables */
  1125. Xextern LVAL xlenv,xlfenv,xldenv,xlvalue,true;
  1126. Xextern LVAL lk_optional,lk_rest,lk_key,lk_aux,lk_allow_other_keys;
  1127. Xextern LVAL s_evalhook,s_applyhook,s_tracelist;
  1128. Xextern LVAL s_lambda,s_macro;
  1129. Xextern LVAL s_unbound;
  1130. Xextern int xlsample;
  1131. Xextern char buf[];
  1132. X
  1133. X/* forward declarations */
  1134. XFORWARD LVAL xlxeval();
  1135. XFORWARD LVAL evalhook();
  1136. XFORWARD LVAL evform();
  1137. XFORWARD LVAL evfun();
  1138. X
  1139. Xint iEvals = 0;            /* Voodoo */
  1140. X
  1141. X/* xleval - evaluate an xlisp expression (checking for *evalhook*) */
  1142. XLVAL xleval(expr)
  1143. X  LVAL expr;
  1144. X{
  1145. X    /* check for control codes */
  1146. X    if (--xlsample <= 0) {
  1147. X    xlsample = SAMPLE;
  1148. X    oscheck();
  1149. X    }
  1150. X
  1151. X    iEvals ++;            /* Voodoo */
  1152. X
  1153. X    /* check for *evalhook* */
  1154. X    if (getvalue(s_evalhook))
  1155. X    return (evalhook(expr));
  1156. X
  1157. X    /* check for nil */
  1158. X    if (null(expr))
  1159. X    return (NIL);
  1160. X
  1161. X    /* dispatch on the node type */
  1162. X    switch (ntype(expr)) {
  1163. X    case CONS:
  1164. X    return (evform(expr));
  1165. X    case SYMBOL:
  1166. X    return (xlgetvalue(expr));
  1167. X    default:
  1168. X    return (expr);
  1169. X    }
  1170. X}
  1171. X
  1172. X#ifdef CURRENTLY_UNUSED
  1173. X/* xlevalenv - evaluate an expression in a specified environment */
  1174. XLVAL xlevalenv(expr,env,fenv)
  1175. X  LVAL expr,env,fenv;
  1176. X{
  1177. X    LVAL oldenv,oldfenv,val;
  1178. X
  1179. X    /* protect some pointers */
  1180. X    xlstkcheck(2);
  1181. X    xlsave(oldenv);
  1182. X    xlsave(oldfenv);
  1183. X
  1184. X    /* establish the new environment */
  1185. X    oldenv = xlenv;
  1186. X    oldfenv = xlfenv;
  1187. X    xlenv = env;
  1188. X    xlfenv = fenv;
  1189. X
  1190. X    /* evaluate the expression */
  1191. X    val = xleval(expr);
  1192. X
  1193. X    /* restore the environment */
  1194. X    xlenv = oldenv;
  1195. X    xlfenv = oldfenv;
  1196. X
  1197. X    /* restore the stack */
  1198. X    xlpopn(2);
  1199. X
  1200. X    /* return the result value */
  1201. X    return (val);
  1202. X}
  1203. X#endif
  1204. X
  1205. X/* xlxeval - evaluate an xlisp expression (bypassing *evalhook*) */
  1206. XLVAL xlxeval(expr)
  1207. X  LVAL expr;
  1208. X{
  1209. X    /* check for nil */
  1210. X    if (null(expr))
  1211. X    return (NIL);
  1212. X
  1213. X    /* dispatch on node type */
  1214. X    switch (ntype(expr)) {
  1215. X    case CONS:
  1216. X    return (evform(expr));
  1217. X    case SYMBOL:
  1218. X    return (xlgetvalue(expr));
  1219. X    default:
  1220. X    return (expr);
  1221. X    }
  1222. X}
  1223. X
  1224. X/* xlapply - apply a function to arguments (already on the stack) */
  1225. XLVAL xlapply(argc)
  1226. X  int argc;
  1227. X{
  1228. X    LVAL *oldargv,fun,val;
  1229. X    int oldargc;
  1230. X    
  1231. X    /* get the function */
  1232. X    fun = xlfp[1];
  1233. X
  1234. X    /* get the functional value of symbols */
  1235. X    if (symbolp(fun)) {
  1236. X    while ((val = getfunction(fun)) == s_unbound)
  1237. X        xlfunbound(fun);
  1238. X    fun = xlfp[1] = val;
  1239. X    }
  1240. X
  1241. X    /* check for nil */
  1242. X    if (null(fun))
  1243. X    xlerror("bad function",fun);
  1244. X
  1245. X    /* dispatch on node type */
  1246. X    switch (ntype(fun)) {
  1247. X    case SUBR:
  1248. X    oldargc = xlargc;
  1249. X    oldargv = xlargv;
  1250. X    xlargc = argc;
  1251. X    xlargv = xlfp + 3;
  1252. X    val = (*getsubr(fun))();
  1253. X    xlargc = oldargc;
  1254. X    xlargv = oldargv;
  1255. X    break;
  1256. X    case CONS:
  1257. X    if (!consp(cdr(fun)))
  1258. X        xlerror("bad function",fun);
  1259. X    if (car(fun) == s_lambda)
  1260. X        fun = xlclose(NIL,
  1261. X                      s_lambda,
  1262. X                      car(cdr(fun)),
  1263. X                      cdr(cdr(fun)),
  1264. X                      xlenv,xlfenv);
  1265. X    else
  1266. X        xlerror("bad function",fun);
  1267. X    /**** fall through into the next case ****/
  1268. X    case CLOSURE:
  1269. X    if (gettype(fun) != s_lambda)
  1270. X        xlerror("bad function",fun);
  1271. X    val = evfun(fun,argc,xlfp+3);
  1272. X    break;
  1273. X    default:
  1274. X    xlerror("bad function",fun);
  1275. X    }
  1276. X
  1277. X    /* remove the call frame */
  1278. X    xlsp = xlfp;
  1279. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  1280. X
  1281. X    /* return the function value */
  1282. X    return (val);
  1283. X}
  1284. X
  1285. X/* evform - evaluate a form */
  1286. XLOCAL LVAL evform(form)
  1287. X  LVAL form;
  1288. X{
  1289. X    LVAL fun,args,val,type;
  1290. X    LVAL tracing=NIL;
  1291. X    LVAL *argv;
  1292. X    int argc;
  1293. X
  1294. X    /* protect some pointers */
  1295. X    xlstkcheck(2);
  1296. X    xlsave(fun);
  1297. X    xlsave(args);
  1298. X
  1299. X    /* get the function and the argument list */
  1300. X    fun = car(form);
  1301. X    args = cdr(form);
  1302. X
  1303. X    /* get the functional value of symbols */
  1304. X    if (symbolp(fun)) {
  1305. X    if (getvalue(s_tracelist) && member(fun,getvalue(s_tracelist)))
  1306. X        tracing = fun;
  1307. X    fun = xlgetfunction(fun);
  1308. X    }
  1309. X
  1310. X    /* check for nil */
  1311. X    if (null(fun))
  1312. X    xlerror("bad function",NIL);
  1313. X
  1314. X    /* dispatch on node type */
  1315. X    switch (ntype(fun)) {
  1316. X    case SUBR:
  1317. X    argv = xlargv;
  1318. X    argc = xlargc;
  1319. X    xlargc = evpushargs(fun,args);
  1320. X    xlargv = xlfp + 3;
  1321. X    trenter(tracing,xlargc,xlargv);
  1322. X    val = (*getsubr(fun))();
  1323. X    trexit(tracing,val);
  1324. X    xlsp = xlfp;
  1325. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  1326. X    xlargv = argv;
  1327. X    xlargc = argc;
  1328. X    break;
  1329. X    case FSUBR:
  1330. X    argv = xlargv;
  1331. X    argc = xlargc;
  1332. X    xlargc = pushargs(fun,args);
  1333. X    xlargv = xlfp + 3;
  1334. X    val = (*getsubr(fun))();
  1335. X    xlsp = xlfp;
  1336. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  1337. X    xlargv = argv;
  1338. X    xlargc = argc;
  1339. X    break;
  1340. X    case CONS:
  1341. X    if (!consp(cdr(fun)))
  1342. X        xlerror("bad function",fun);
  1343. X    if ((type = car(fun)) == s_lambda)
  1344. X         fun = xlclose(NIL,
  1345. X                       s_lambda,
  1346. X                       car(cdr(fun)),
  1347. X                       cdr(cdr(fun)),
  1348. X                       xlenv,xlfenv);
  1349. X    else
  1350. X        xlerror("bad function",fun);
  1351. X    /**** fall through into the next case ****/
  1352. X    case CLOSURE:
  1353. X    if (gettype(fun) == s_lambda) {
  1354. X        argc = evpushargs(fun,args);
  1355. X        argv = xlfp + 3;
  1356. X        trenter(tracing,argc,argv);
  1357. X        val = evfun(fun,argc,argv);
  1358. X        trexit(tracing,val);
  1359. X        xlsp = xlfp;
  1360. X        xlfp = xlfp - (int)getfixnum(*xlfp);
  1361. X    }
  1362. X    else {
  1363. X        macroexpand(fun,args,&fun);
  1364. X        val = xleval(fun);
  1365. X    }
  1366. X    break;
  1367. X    default:
  1368. X    xlerror("bad function",fun);
  1369. X    }
  1370. X
  1371. X    /* restore the stack */
  1372. X    xlpopn(2);
  1373. X
  1374. X    /* return the result value */
  1375. X    return (val);
  1376. X}
  1377. X
  1378. X/* xlexpandmacros - expand macros in a form */
  1379. XLVAL xlexpandmacros(form)
  1380. X  LVAL form;
  1381. X{
  1382. X    LVAL fun,args;
  1383. X    
  1384. X    /* protect some pointers */
  1385. X    xlstkcheck(3);
  1386. X    xlprotect(form);
  1387. X    xlsave(fun);
  1388. X    xlsave(args);
  1389. X
  1390. X    /* expand until the form isn't a macro call */
  1391. X    while (consp(form)) {
  1392. X    fun = car(form);        /* get the macro name */
  1393. X    args = cdr(form);        /* get the arguments */
  1394. X    if (!symbolp(fun) || !fboundp(fun))
  1395. X        break;
  1396. X    fun = xlgetfunction(fun);    /* get the expansion function */
  1397. X    if (!macroexpand(fun,args,&form))
  1398. X        break;
  1399. X    }
  1400. X
  1401. X    /* restore the stack and return the expansion */
  1402. X    xlpopn(3);
  1403. X    return (form);
  1404. X}
  1405. X
  1406. X/* macroexpand - expand a macro call */
  1407. Xint macroexpand(fun,args,pval)
  1408. X  LVAL fun,args,*pval;
  1409. X{
  1410. X    LVAL *argv;
  1411. X    int argc;
  1412. X    
  1413. X    /* make sure it's really a macro call */
  1414. X    if (!closurep(fun) || gettype(fun) != s_macro)
  1415. X    return (FALSE);
  1416. X    
  1417. X    /* call the expansion function */
  1418. X    argc = pushargs(fun,args);
  1419. X    argv = xlfp + 3;
  1420. X    *pval = evfun(fun,argc,argv);
  1421. X    xlsp = xlfp;
  1422. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  1423. X    return (TRUE);
  1424. X}
  1425. X
  1426. X/* evalhook - call the evalhook function */
  1427. XLOCAL LVAL evalhook(expr)
  1428. X  LVAL expr;
  1429. X{
  1430. X    LVAL *newfp,olddenv,val;
  1431. X
  1432. X    /* create the new call frame */
  1433. X    newfp = xlsp;
  1434. X    pusharg(cvfixnum((FIXTYPE)(newfp - xlfp)));
  1435. X    pusharg(getvalue(s_evalhook));
  1436. X    pusharg(cvfixnum((FIXTYPE)2));
  1437. X    pusharg(expr);
  1438. X    pusharg(cons(xlenv,xlfenv));
  1439. X    xlfp = newfp;
  1440. X
  1441. X    /* rebind the hook functions to nil */
  1442. X    olddenv = xldenv;
  1443. X    xldbind(s_evalhook,NIL);
  1444. X    xldbind(s_applyhook,NIL);
  1445. X
  1446. X    /* call the hook function */
  1447. X    val = xlapply(2);
  1448. X
  1449. X    /* unbind the symbols */
  1450. X    xlunbind(olddenv);
  1451. X
  1452. X    /* return the value */
  1453. X    return (val);
  1454. X}
  1455. X
  1456. X/* evpushargs - evaluate and push a list of arguments */
  1457. XLOCAL int evpushargs(fun,args)
  1458. X  LVAL fun,args;
  1459. X{
  1460. X    LVAL *newfp;
  1461. X    int argc;
  1462. X    
  1463. X    /* protect the argument list */
  1464. X    xlprot1(args);
  1465. X
  1466. X    /* build a new argument stack frame */
  1467. X    newfp = xlsp;
  1468. X    pusharg(cvfixnum((FIXTYPE)(newfp - xlfp)));
  1469. X    pusharg(fun);
  1470. X    pusharg(NIL); /* will be argc */
  1471. X
  1472. X    /* evaluate and push each argument */
  1473. X    for (argc = 0; consp(args); args = cdr(args), ++argc)
  1474. X    pusharg(xleval(car(args)));
  1475. X
  1476. X    /* establish the new stack frame */
  1477. X    newfp[2] = cvfixnum((FIXTYPE)argc);
  1478. X    xlfp = newfp;
  1479. X    
  1480. X    /* restore the stack */
  1481. X    xlpop();
  1482. X
  1483. X    /* return the number of arguments */
  1484. X    return (argc);
  1485. X}
  1486. X
  1487. X/* pushargs - push a list of arguments */
  1488. Xint pushargs(fun,args)
  1489. X  LVAL fun,args;
  1490. X{
  1491. X    LVAL *newfp;
  1492. X    int argc;
  1493. X    
  1494. X    /* build a new argument stack frame */
  1495. X    newfp = xlsp;
  1496. X    pusharg(cvfixnum((FIXTYPE)(newfp - xlfp)));
  1497. X    pusharg(fun);
  1498. X    pusharg(NIL); /* will be argc */
  1499. X
  1500. X    /* push each argument */
  1501. X    for (argc = 0; consp(args); args = cdr(args), ++argc)
  1502. X    pusharg(car(args));
  1503. X
  1504. X    /* establish the new stack frame */
  1505. X    newfp[2] = cvfixnum((FIXTYPE)argc);
  1506. X    xlfp = newfp;
  1507. X
  1508. X    /* return the number of arguments */
  1509. X    return (argc);
  1510. X}
  1511. X
  1512. X/* makearglist - make a list of the remaining arguments */
  1513. XLVAL makearglist(argc,argv)
  1514. X  int argc; LVAL *argv;
  1515. X{
  1516. X    LVAL list,this,last;
  1517. X    xlsave1(list);
  1518. X    for (last = NIL; --argc >= 0; last = this) {
  1519. X    this = cons(*argv++,NIL);
  1520. X    if (last) rplacd(last,this);
  1521. X    else list = this;
  1522. X    }
  1523. X    xlpop();
  1524. X    return (list);
  1525. X}
  1526. X
  1527. X/* evfun - evaluate a function */
  1528. XLOCAL LVAL evfun(fun,argc,argv)
  1529. X  LVAL fun; int argc; LVAL *argv;
  1530. X{
  1531. X    LVAL oldenv,oldfenv,cptr,name,val;
  1532. X    CONTEXT cntxt;
  1533. X
  1534. X    /* protect some pointers */
  1535. X    xlstkcheck(3);
  1536. X    xlsave(oldenv);
  1537. X    xlsave(oldfenv);
  1538. X    xlsave(cptr);
  1539. X
  1540. X    /* create a new environment frame */
  1541. X    oldenv = xlenv;
  1542. X    oldfenv = xlfenv;
  1543. X    xlenv = xlframe(xlgetenv(fun));
  1544. X    xlfenv = getfenv(fun);
  1545. X
  1546. X    /* bind the formal parameters */
  1547. X    xlabind(fun,argc,argv);
  1548. X
  1549. X    /* setup the implicit block */
  1550. X    if (name = getname(fun))
  1551. X    xlbegin(&cntxt,CF_RETURN,name);
  1552. X
  1553. X    /* execute the block */
  1554. X    if (name && xlsetjmp(cntxt.c_jmpbuf))
  1555. X    val = xlvalue;
  1556. X    else
  1557. X    for (val = NIL, cptr = getbody(fun); consp(cptr); cptr = cdr(cptr))
  1558. X        val = xleval(car(cptr));
  1559. X
  1560. X    /* finish the block context */
  1561. X    if (name)
  1562. X    xlend(&cntxt);
  1563. X
  1564. X    /* restore the environment */
  1565. X    xlenv = oldenv;
  1566. X    xlfenv = oldfenv;
  1567. X
  1568. X    /* restore the stack */
  1569. X    xlpopn(3);
  1570. X
  1571. X    /* return the result value */
  1572. X    return (val);
  1573. X}
  1574. X
  1575. X/* xlclose - create a function closure */
  1576. XLVAL xlclose(name,type,fargs,body,env,fenv)
  1577. X  LVAL name,type,fargs,body,env,fenv;
  1578. X{
  1579. X    LVAL closure,key,arg,def,svar,new,last;
  1580. X    char keyname[STRMAX+2];
  1581. X
  1582. X    /* protect some pointers */
  1583. X    xlsave1(closure);
  1584. X
  1585. X    /* create the closure object */
  1586. X    closure = newclosure(name,type,env,fenv);
  1587. X    setlambda(closure,fargs);
  1588. X    setbody(closure,body);
  1589. X
  1590. X    /* handle each required argument */
  1591. X    last = NIL;
  1592. X    while (consp(fargs) && (arg = car(fargs)) && !iskey(arg)) {
  1593. X
  1594. X    /* make sure the argument is a symbol */
  1595. X    if (!symbolp(arg))
  1596. X        badarglist();
  1597. X
  1598. X    /* create a new argument list entry */
  1599. X    new = cons(arg,NIL);
  1600. X
  1601. X    /* link it into the required argument list */
  1602. X    if (last)
  1603. X        rplacd(last,new);
  1604. X    else
  1605. X        setargs(closure,new);
  1606. X    last = new;
  1607. X
  1608. X    /* move the formal argument list pointer ahead */
  1609. X    fargs = cdr(fargs);
  1610. X    }
  1611. X
  1612. X    /* check for the '&optional' keyword */
  1613. X    if (consp(fargs) && car(fargs) == lk_optional) {
  1614. X    fargs = cdr(fargs);
  1615. X
  1616. X    /* handle each optional argument */
  1617. X    last = NIL;
  1618. X    while (consp(fargs) && (arg = car(fargs)) && !iskey(arg)) {
  1619. X
  1620. X        /* get the default expression and specified-p variable */
  1621. X        def = svar = NIL;
  1622. X        if (consp(arg)) {
  1623. X        if (def = cdr(arg))
  1624. X            if (consp(def)) {
  1625. X            if (svar = cdr(def))
  1626. X                if (consp(svar)) {
  1627. X                svar = car(svar);
  1628. X                if (!symbolp(svar))
  1629. X                    badarglist();
  1630. X                }
  1631. X                else
  1632. X                badarglist();
  1633. X            def = car(def);
  1634. X            }
  1635. X            else
  1636. X            badarglist();
  1637. X        arg = car(arg);
  1638. X        }
  1639. X
  1640. X        /* make sure the argument is a symbol */
  1641. X        if (!symbolp(arg))
  1642. X        badarglist();
  1643. X
  1644. X        /* create a fully expanded optional expression */
  1645. X        new = cons(cons(arg,cons(def,cons(svar,NIL))),NIL);
  1646. X
  1647. X        /* link it into the optional argument list */
  1648. X        if (last)
  1649. X        rplacd(last,new);
  1650. X        else
  1651. X        setoargs(closure,new);
  1652. X        last = new;
  1653. X        
  1654. X        /* move the formal argument list pointer ahead */
  1655. X        fargs = cdr(fargs);
  1656. X    }
  1657. X    }
  1658. X
  1659. X    /* check for the '&rest' keyword */
  1660. X    if (consp(fargs) && car(fargs) == lk_rest) {
  1661. X    fargs = cdr(fargs);
  1662. X
  1663. X    /* get the &rest argument */
  1664. X    if (consp(fargs) && (arg = car(fargs)) && !iskey(arg) && symbolp(arg))
  1665. X        setrest(closure,arg);
  1666. X    else
  1667. X        badarglist();
  1668. X
  1669. X    /* move the formal argument list pointer ahead */
  1670. X    fargs = cdr(fargs);
  1671. X    }
  1672. X
  1673. X    /* check for the '&key' keyword */
  1674. X    if (consp(fargs) && car(fargs) == lk_key) {
  1675. X    fargs = cdr(fargs);
  1676. X
  1677. X     /* handle each key argument */
  1678. X    last = NIL;
  1679. X    while (consp(fargs) && (arg = car(fargs)) && !iskey(arg)) {
  1680. X
  1681. X        /* get the default expression and specified-p variable */
  1682. X        def = svar = NIL;
  1683. X        if (consp(arg)) {
  1684. X        if (def = cdr(arg))
  1685. X            if (consp(def)) {
  1686. X            if (svar = cdr(def))
  1687. X                if (consp(svar)) {
  1688. X                svar = car(svar);
  1689. X                if (!symbolp(svar))
  1690. X                    badarglist();
  1691. X                }
  1692. X                else
  1693. X                badarglist();
  1694. X            def = car(def);
  1695. X            }
  1696. X            else
  1697. X            badarglist();
  1698. X        arg = car(arg);
  1699. X        }
  1700. X
  1701. X        /* get the keyword and the variable */
  1702. X        if (consp(arg)) {
  1703. X        key = car(arg);
  1704. X        if (!symbolp(key))
  1705. X            badarglist();
  1706. X        if (arg = cdr(arg))
  1707. X            if (consp(arg))
  1708. X            arg = car(arg);
  1709. X            else
  1710. X            badarglist();
  1711. X        }
  1712. X        else if (symbolp(arg)) {
  1713. X        strcpy(keyname,":");
  1714. X        strcat(keyname,getstring(getpname(arg)));
  1715. X        key = xlenter(keyname);
  1716. X        }
  1717. X
  1718. X        /* make sure the argument is a symbol */
  1719. X        if (!symbolp(arg))
  1720. X        badarglist();
  1721. X
  1722. X        /* create a fully expanded key expression */
  1723. X        new = cons(cons(key,cons(arg,cons(def,cons(svar,NIL)))),NIL);
  1724. X
  1725. X        /* link it into the optional argument list */
  1726. X        if (last)
  1727. X        rplacd(last,new);
  1728. X        else
  1729. X        setkargs(closure,new);
  1730. X        last = new;
  1731. X
  1732. X        /* move the formal argument list pointer ahead */
  1733. X        fargs = cdr(fargs);
  1734. X    }
  1735. X    }
  1736. X
  1737. X    /* check for the '&allow-other-keys' keyword */
  1738. X    if (consp(fargs) && car(fargs) == lk_allow_other_keys)
  1739. X    fargs = cdr(fargs);    /* this is the default anyway */
  1740. X
  1741. X    /* check for the '&aux' keyword */
  1742. X    if (consp(fargs) && car(fargs) == lk_aux) {
  1743. X    fargs = cdr(fargs);
  1744. X
  1745. X    /* handle each aux argument */
  1746. X    last = NIL;
  1747. X    while (consp(fargs) && (arg = car(fargs)) && !iskey(arg)) {
  1748. X
  1749. X        /* get the initial value */
  1750. X        def = NIL;
  1751. X        if (consp(arg)) {
  1752. X        if (def = cdr(arg))
  1753. X            if (consp(def))
  1754. X            def = car(def);
  1755. X            else
  1756. X            badarglist();
  1757. X        arg = car(arg);
  1758. X        }
  1759. X
  1760. X        /* make sure the argument is a symbol */
  1761. X        if (!symbolp(arg))
  1762. X        badarglist();
  1763. X
  1764. X        /* create a fully expanded aux expression */
  1765. X        new = cons(cons(arg,cons(def,NIL)),NIL);
  1766. X
  1767. X        /* link it into the aux argument list */
  1768. X        if (last)
  1769. X        rplacd(last,new);
  1770. X        else
  1771. X        setaargs(closure,new);
  1772. X        last = new;
  1773. X
  1774. X        /* move the formal argument list pointer ahead */
  1775. X        fargs = cdr(fargs);
  1776. X    }
  1777. X    }
  1778. X
  1779. X    /* make sure this is the end of the formal argument list */
  1780. X    if (fargs)
  1781. X    badarglist();
  1782. X
  1783. X    /* restore the stack */
  1784. X    xlpop();
  1785. X
  1786. X    /* return the new closure */
  1787. X    return (closure);
  1788. X}
  1789. X
  1790. X/* xlabind - bind the arguments for a function */
  1791. Xxlabind(fun,argc,argv)
  1792. X  LVAL fun; int argc; LVAL *argv;
  1793. X{
  1794. X    LVAL *kargv,fargs,key,arg,def,svar,p;
  1795. X    int rargc,kargc;
  1796. X    
  1797. X    /* protect some pointers */
  1798. X    xlsave1(def);
  1799. X
  1800. X    /* bind each required argument */
  1801. X    for (fargs = getargs(fun); fargs; fargs = cdr(fargs)) {
  1802. X
  1803. X    /* make sure there is an actual argument */
  1804. X    if (--argc < 0)
  1805. X        xlfail("too few arguments");
  1806. X
  1807. X    /* bind the formal variable to the argument value */
  1808. X    xlbind(car(fargs),*argv++);
  1809. X    }
  1810. X
  1811. X    /* bind each optional argument */
  1812. X    for (fargs = getoargs(fun); fargs; fargs = cdr(fargs)) {
  1813. X
  1814. X    /* get argument, default and specified-p variable */
  1815. X    p = car(fargs);
  1816. X    arg = car(p); p = cdr(p);
  1817. X    def = car(p); p = cdr(p);
  1818. X    svar = car(p);
  1819. X
  1820. X    /* bind the formal variable to the argument value */
  1821. X    if (--argc >= 0) {
  1822. X        xlbind(arg,*argv++);
  1823. X        if (svar) xlbind(svar,true);
  1824. X    }
  1825. X
  1826. X    /* bind the formal variable to the default value */
  1827. X    else {
  1828. X        if (def) def = xleval(def);
  1829. X        xlbind(arg,def);
  1830. X        if (svar) xlbind(svar,NIL);
  1831. X    }
  1832. X    }
  1833. X
  1834. X    /* save the count of the &rest of the argument list */
  1835. X    rargc = argc;
  1836. X    
  1837. X    /* handle '&rest' argument */
  1838. X    if (arg = getrest(fun)) {
  1839. X    def = makearglist(argc,argv);
  1840. X    xlbind(arg,def);
  1841. X    argc = 0;
  1842. X    }
  1843. X
  1844. X    /* handle '&key' arguments */
  1845. X    if (fargs = getkargs(fun)) {
  1846. X    for (; fargs; fargs = cdr(fargs)) {
  1847. X
  1848. X        /* get keyword, argument, default and specified-p variable */
  1849. X        p = car(fargs);
  1850. X        key = car(p); p = cdr(p);
  1851. X        arg = car(p); p = cdr(p);
  1852. X        def = car(p); p = cdr(p);
  1853. X        svar = car(p);
  1854. X
  1855. X        /* look for the keyword in the actual argument list */
  1856. X        for (kargv = argv, kargc = rargc; (kargc -= 2) >= 0; kargv += 2)
  1857. X        if (*kargv == key)
  1858. X            break;
  1859. X
  1860. X        /* bind the formal variable to the argument value */
  1861. X        if (kargc >= 0) {
  1862. X        xlbind(arg,*++kargv);
  1863. X        if (svar) xlbind(svar,true);
  1864. X        }
  1865. X
  1866. X        /* bind the formal variable to the default value */
  1867. X        else {
  1868. X        if (def) def = xleval(def);
  1869. X        xlbind(arg,def);
  1870. X        if (svar) xlbind(svar,NIL);
  1871. X        }
  1872. X    }
  1873. X    argc = 0;
  1874. X    }
  1875. X
  1876. X    /* check for the '&aux' keyword */
  1877. X    for (fargs = getaargs(fun); fargs; fargs = cdr(fargs)) {
  1878. X
  1879. X    /* get argument and default */
  1880. X    p = car(fargs);
  1881. X    arg = car(p); p = cdr(p);
  1882. X    def = car(p);
  1883. X
  1884. X    /* bind the auxiliary variable to the initial value */
  1885. X    if (def) def = xleval(def);
  1886. X    xlbind(arg,def);
  1887. X    }
  1888. X
  1889. X    /* make sure there aren't too many arguments */
  1890. X    if (argc > 0)
  1891. X    xlfail("too many arguments");
  1892. X
  1893. X    /* restore the stack */
  1894. X    xlpop();
  1895. X}
  1896. X
  1897. X/* doenter - print trace information on function entry */
  1898. XLOCAL doenter(sym,argc,argv)
  1899. X  LVAL sym; int argc; LVAL *argv;
  1900. X{
  1901. X    extern int xltrcindent;
  1902. X    int i;
  1903. X    
  1904. X    /* indent to the current trace level */
  1905. X    for (i = 0; i < xltrcindent; ++i)
  1906. X    trcputstr(" ");
  1907. X    ++xltrcindent;
  1908. X
  1909. X    /* display the function call */
  1910. X    sprintf(buf,"Entering: %s, Argument list: (",getstring(getpname(sym)));
  1911. X    trcputstr(buf);
  1912. X    while (--argc >= 0) {
  1913. X    trcprin1(*argv++);
  1914. X    if (argc) trcputstr(" ");
  1915. X    }
  1916. X    trcputstr(")\n");
  1917. X}
  1918. X
  1919. X/* doexit - print trace information for function/macro exit */
  1920. XLOCAL doexit(sym,val)
  1921. X  LVAL sym,val;
  1922. X{
  1923. X    extern int xltrcindent;
  1924. X    int i;
  1925. X    
  1926. X    /* indent to the current trace level */
  1927. X    --xltrcindent;
  1928. X    for (i = 0; i < xltrcindent; ++i)
  1929. X    trcputstr(" ");
  1930. X    
  1931. X    /* display the function value */
  1932. X    sprintf(buf,"Exiting: %s, Value: ",getstring(getpname(sym)));
  1933. X    trcputstr(buf);
  1934. X    trcprin1(val);
  1935. X    trcputstr("\n");
  1936. X}
  1937. X
  1938. X/* member - is 'x' a member of 'list'? */
  1939. XLOCAL int member(x,list)
  1940. X  LVAL x,list;
  1941. X{
  1942. X    for (; consp(list); list = cdr(list))
  1943. X    if (x == car(list))
  1944. X        return (TRUE);
  1945. X    return (FALSE);
  1946. X}
  1947. X
  1948. X/* xlunbound - signal an unbound variable error */
  1949. Xxlunbound(sym)
  1950. X  LVAL sym;
  1951. X{
  1952. X    xlcerror("try evaluating symbol again","unbound variable",sym);
  1953. X}
  1954. X
  1955. X/* xlfunbound - signal an unbound function error */
  1956. Xxlfunbound(sym)
  1957. X  LVAL sym;
  1958. X{
  1959. X    xlcerror("try evaluating symbol again","unbound function",sym);
  1960. X}
  1961. X
  1962. X/* xlstkoverflow - signal a stack overflow error */
  1963. Xxlstkoverflow()
  1964. X{
  1965. X    xlabort("evaluation stack overflow");
  1966. X}
  1967. X
  1968. X/* xlargstkoverflow - signal an argument stack overflow error */
  1969. Xxlargstkoverflow()
  1970. X{
  1971. X    xlabort("argument stack overflow");
  1972. X}
  1973. X
  1974. X/* badarglist - report a bad argument list error */
  1975. XLOCAL badarglist()
  1976. X{
  1977. X    xlfail("bad formal argument list");
  1978. X}
  1979. END_OF_FILE
  1980. if test 21287 -ne `wc -c <'src/xlisp/xcore/c/xleval.c'`; then
  1981.     echo shar: \"'src/xlisp/xcore/c/xleval.c'\" unpacked with wrong size!
  1982. fi
  1983. # end of 'src/xlisp/xcore/c/xleval.c'
  1984. fi
  1985. if test -f 'src/xlisp/xcore/c/xlftab.c' -a "${1}" != "-c" ; then 
  1986.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlftab.c'\"
  1987. else
  1988. echo shar: Extracting \"'src/xlisp/xcore/c/xlftab.c'\" \(22885 characters\)
  1989. sed "s/^X//" >'src/xlisp/xcore/c/xlftab.c' <<'END_OF_FILE'
  1990. X/* xlftab.c - xlisp function table */
  1991. X/*    Copyright (c) 1985, by David Michael Betz */
  1992. X
  1993. X#include "xlisp.h"
  1994. X
  1995. X/* external functions */
  1996. Xextern LVAL
  1997. X    rmhash(),rmquote(),rmdquote(),rmbquote(),rmcomma(),
  1998. X    clnew(),clisnew(),clanswer(),
  1999. X    obisnew(),obclass(),obshow(),
  2000. X    rmlpar(),rmrpar(),rmsemi(),
  2001. X    xeval(),xapply(),xfuncall(),xquote(),xfunction(),xbquote(),
  2002. X    xlambda(),xset(),xsetq(),xsetf(),xdefun(),xdefmacro(),
  2003. X    xgensym(),xmakesymbol(),xintern(),
  2004. X    xsymname(),xsymvalue(),xsymplist(),
  2005. X    xget(),xputprop(),xremprop(),
  2006. X    xhash(),xmkarray(),xaref(),
  2007. X    xcar(),xcdr(),
  2008. X    xcaar(),xcadr(),xcdar(),xcddr(),
  2009. X    xcaaar(),xcaadr(),xcadar(),xcaddr(),
  2010. X    xcdaar(),xcdadr(),xcddar(),xcdddr(),
  2011. X    xcaaaar(),xcaaadr(),xcaadar(),xcaaddr(),
  2012. X    xcadaar(),xcadadr(),xcaddar(),xcadddr(),
  2013. X    xcdaaar(),xcdaadr(),xcdadar(),xcdaddr(),
  2014. X    xcddaar(),xcddadr(),xcdddar(),xcddddr(),
  2015. X    xcons(),xlist(),xappend(),xreverse(),xlast(),xnth(),xnthcdr(),
  2016. X    xmember(),xassoc(),xsubst(),xsublis(),xlength(),xsort(),
  2017. X    xremove(),xremif(),xremifnot(),
  2018. X    xmapc(),xmapcar(),xmapl(),xmaplist(),
  2019. X    xrplca(),xrplcd(),xnconc(),
  2020. X    xdelete(),xdelif(),xdelifnot(),
  2021. X    xatom(),xsymbolp(),xnumberp(),xboundp(),xnull(),xlistp(),xendp(),xconsp(),
  2022. X    xeq(),xeql(),xequal(),
  2023. X    xcond(),xcase(),xand(),xor(),xlet(),xletstar(),xif(),
  2024. X    xprog(),xprogstar(),xprog1(),xprog2(),xprogn(),xgo(),xreturn(),
  2025. X    xcatch(),xthrow(),
  2026. X    xerror(),xcerror(),xbreak(),
  2027. X    xcleanup(),xtoplevel(),xcontinue(),xerrset(),
  2028. X    xbaktrace(),xevalhook(),
  2029. X    xdo(),xdostar(),xdolist(),xdotimes(),
  2030. X    xminusp(),xzerop(),xplusp(),xevenp(),xoddp(),
  2031. X    xfix(),xfloat(),
  2032. X    xgcd(),xadd(),xsub(),xmul(),xdiv(),xrem(),xmin(),xmax(),xabs(),
  2033. X    xadd1(),xsub1(),xlogand(),xlogior(),xlogxor(),xlognot(),
  2034. X    xsin(),xcos(),xtan(),xexpt(),xexp(),xsqrt(),xrand(),
  2035. X    xlss(),xleq(),xequ(),xneq(),xgeq(),xgtr(),
  2036. X    xstrcat(),xsubseq(),xstring(),xchar(),
  2037. X    xread(),xprint(),xprin1(),xprinc(),xterpri(),
  2038. X    xflatsize(),xflatc(),
  2039. X    xopen(),xclose(),xrdchar(),xpkchar(),xwrchar(),xreadline(),
  2040. X    xload(),xtranscript(),
  2041. X    xtype(),xexit(),xpeek(),xpoke(),xaddrs(),
  2042. X    xvector(),xblock(),xrtnfrom(),xtagbody(),
  2043. X    xpsetq(),xflet(),xlabels(),xmacrolet(),xunwindprotect(),xpp(),
  2044. X    xstrlss(),xstrleq(),xstreql(),xstrneq(),xstrgeq(),xstrgtr(),
  2045. X    xstrilss(),xstrileq(),xstrieql(),xstrineq(),xstrigeq(),xstrigtr(),
  2046. X    xupcase(),xdowncase(),xnupcase(),xndowncase(),
  2047. X    xtrim(),xlefttrim(),xrighttrim(),
  2048. X    xuppercasep(),xlowercasep(),xbothcasep(),xdigitp(),xalphanumericp(),
  2049. X    xcharcode(),xcodechar(),xchupcase(),xchdowncase(),xdigitchar(),
  2050. X    xchrlss(),xchrleq(),xchreql(),xchrneq(),xchrgeq(),xchrgtr(),
  2051. X    xchrilss(),xchrileq(),xchrieql(),xchrineq(),xchrigeq(),xchrigtr(),
  2052. X    xintegerp(),xfloatp(),xstringp(),xarrayp(),xstreamp(),xobjectp(),
  2053. X    xwhen(),xunless(),xloop(),
  2054. X    xsymfunction(),xfboundp(),xsend(),xsendsuper(),
  2055. X    xprogv(),xrdbyte(),xwrbyte(),xformat(),
  2056. X    xcharp(),xcharint(),xintchar(),
  2057. X    xmkstrinput(),xmkstroutput(),xgetstroutput(),xgetlstoutput(),
  2058. X    xgetlambda(),xmacroexpand(),x1macroexpand(),
  2059. X    xtrace(),xuntrace(),
  2060. X    xdefstruct(),xmkstruct(),xcpystruct(),xstrref(),xstrset(),xstrtypep(),
  2061. X    xasin(),xacos(),xatan(),
  2062. X    Prim_POPEN(), Prim_PCLOSE(), Prim_SYSTEM(),    /* NPM */
  2063. X    Prim_FSCANF_FIXNUM(), Prim_FSCANF_STRING(), Prim_FSCANF_FLONUM(), /* NPM */
  2064. X    Prim_COPY_ARRAY(), Prim_ARRAY_INSERT_POS(), Prim_ARRAY_DELETE_POS(); /* NPM */
  2065. X
  2066. Xextern LVAL xosenvget(); /* JSP */
  2067. Xextern void xlinclude_hybrid_prims(); /* Voodoo */
  2068. X
  2069. X/* Include hybrid-class functions: *//* JSP */
  2070. X#define MODULE_XLFTAB_C_GLOBALS
  2071. X#include "../../xmodules.h"
  2072. X#undef MODULE_XLFTAB_C_GLOBALS
  2073. X
  2074. X/* functions specific to xldmem.c */
  2075. XLVAL xgc(),xexpand(),xalloc(),xmem();
  2076. X#ifdef SAVERESTORE
  2077. XLVAL xsave(),xrestore();
  2078. X#endif
  2079. X
  2080. X/* include system dependent definitions */
  2081. X#include "osdefs.h"
  2082. X
  2083. X/* SUBR/FSUBR indicator */
  2084. X#define S    SUBR
  2085. X#define F    FSUBR
  2086. X
  2087. X/* forward declarations */
  2088. XLVAL xnotimp();
  2089. X
  2090. X/* the function table */
  2091. XFUNDEF *funtab;
  2092. X
  2093. X/* and its associated parts */ /* Voodoo */
  2094. X#define xlisp_prim_max 500
  2095. Xint    iPrimCount;
  2096. X
  2097. X
  2098. X/* xlfinit - setup xlisp function table */ /* Voodoo */
  2099. Xvoid xlfinit()
  2100. X{
  2101. X    int        iIndex;
  2102. X
  2103. X    if (funtab = (FUNDEF *) malloc(xlisp_prim_max * sizeof(FUNDEF))) {
  2104. X    
  2105. X    iPrimCount = 0;
  2106. X
  2107. X    /* load xlisp native prims, updates iPrimCount global */
  2108. X    xlinclude_native_prims();      
  2109. X    
  2110. X    /* load user's hybrid prims, updates iPrimCount global */
  2111. X    xlinclude_hybrid_prims();      
  2112. X    
  2113. X    /* reserve a slot for sentinel */
  2114. X    funtab[iPrimCount].fd_name = 0;
  2115. X    funtab[iPrimCount].fd_type = 0;
  2116. X    funtab[iPrimCount].fd_subr = 0;
  2117. X    iPrimCount ++;
  2118. X
  2119. X    /* allocate permanent global funtable of exact size */
  2120. X    funtab = (FUNDEF *) realloc(funtab, iPrimCount * sizeof(FUNDEF));
  2121. X    }
  2122. X
  2123. X    } /* xlfinit */
  2124. X
  2125. X
  2126. X
  2127. X/*  xldefine_prim - enter xlisp prim into xlisp function table */
  2128. Xvoid xldefine_prim(sName, iType, pFun)  /* Voodoo */
  2129. X    char        *sName;
  2130. X    int            iType;
  2131. X    LVAL         (*pFun)();
  2132. X{
  2133. X    funtab[iPrimCount].fd_name = sName;        
  2134. X    funtab[iPrimCount].fd_type = iType;        
  2135. X    funtab[iPrimCount].fd_subr = pFun;        
  2136. X    iPrimCount ++;
  2137. X    }   
  2138. X
  2139. X
  2140. X
  2141. X/* xnotimp - function table entries that are currently not implemented */
  2142. XLOCAL LVAL xnotimp()
  2143. X{
  2144. X    xlfail("function not implemented");
  2145. X}
  2146. X
  2147. X/* funtab_offset - find given fn in funtab. */        /* JSP */
  2148. X/* (Obviates need for hacks like FT_CLNEW.) */          /* JSP */
  2149. XLOCAL int funtab_index = 0; /* For O(1) lookup time on ordered requests. */
  2150. Xfuntab_offset(fn)                    /* JSP */
  2151. XLVAL        (*fn)();                    /* JSP */
  2152. X{                            /* JSP */
  2153. X    int wrapCount = 0;                    /* JSP */
  2154. X    while (wrapCount < 2) {                /* JSP */
  2155. X        LVAL (*e)() = funtab[ funtab_index ].fd_subr;    /* JSP */
  2156. X        if (e == fn)   return funtab_index;        /* JSP */
  2157. X        if (e)              ++funtab_index;        /* JSP */
  2158. X        else {++wrapCount;    funtab_index = 0;}    /* JSP */
  2159. X    }                            /* JSP */
  2160. X    xlfatal("funtab_offset: internal error");        /* JSP */
  2161. X}                            /* JSP */
  2162. X
  2163. X
  2164. X
  2165. X
  2166. Xxlinclude_native_prims()
  2167. X{
  2168. X    /* read macro functions */
  2169. X
  2170. X    
  2171. Xxldefine_prim(NULL,        S, rmhash        ); /*   0 */
  2172. Xxldefine_prim(NULL,        S, rmquote        ); /*   1 */
  2173. Xxldefine_prim(NULL,        S, rmdquote        ); /*   2 */
  2174. Xxldefine_prim(NULL,        S, rmbquote        ); /*   3 */
  2175. Xxldefine_prim(NULL,        S, rmcomma        ); /*   4 */
  2176. Xxldefine_prim(NULL,        S, rmlpar        ); /*   5 */
  2177. Xxldefine_prim(NULL,        S, rmrpar        ); /*   6 */
  2178. Xxldefine_prim(NULL,        S, rmsemi        ); /*   7 */
  2179. Xxldefine_prim(NULL,        S, xnotimp        ); /*   8 */
  2180. X#ifdef ORIGINAL
  2181. Xxldefine_prim(NULL,        S, xnotimp        ); /*   9 */
  2182. X#else
  2183. X    /* BUGGO,need to put envget somewhere else. */
  2184. Xxldefine_prim("GETENV",        S, xosenvget        ); /*   9 */
  2185. X#endif
  2186. X    
  2187. X    /* methods */
  2188. Xxldefine_prim(NULL,        S, clnew        ); /*  10 */
  2189. Xxldefine_prim(NULL,        S, clisnew        ); /*  11 */
  2190. Xxldefine_prim(NULL,        S, clanswer        ); /*  12 */
  2191. Xxldefine_prim(NULL,        S, obisnew        ); /*  13 */
  2192. Xxldefine_prim(NULL,        S, obclass        ); /*  14 */
  2193. Xxldefine_prim(NULL,        S, obshow        ); /*  15 */
  2194. Xxldefine_prim(NULL,        S, xnotimp        ); /*  16 */
  2195. Xxldefine_prim(NULL,        S, xnotimp        ); /*  17 */
  2196. Xxldefine_prim(NULL,        S, xnotimp        ); /*  18 */
  2197. Xxldefine_prim(NULL,        S, xnotimp        ); /*  19 */
  2198. X    
  2199. X    /* evaluator functions */
  2200. Xxldefine_prim("EVAL",        S, xeval        ); /*  20 */
  2201. Xxldefine_prim("APPLY",        S, xapply        ); /*  21 */
  2202. Xxldefine_prim("FUNCALL",    S, xfuncall        ); /*  22 */
  2203. Xxldefine_prim("QUOTE",        F, xquote        ); /*  23 */
  2204. Xxldefine_prim("FUNCTION",    F, xfunction        ); /*  24 */
  2205. Xxldefine_prim("BACKQUOTE",    F, xbquote        ); /*  25 */
  2206. Xxldefine_prim("LAMBDA",        F, xlambda        ); /*  26 */
  2207. X    
  2208. X    /* symbol functions */
  2209. Xxldefine_prim("SET",        S, xset            ); /*  27 */
  2210. Xxldefine_prim("SETQ",        F, xsetq        ); /*  28 */
  2211. Xxldefine_prim("SETF",        F, xsetf        ); /*  29 */
  2212. Xxldefine_prim("DEFUN",        F, xdefun        ); /*  30 */
  2213. Xxldefine_prim("DEFMACRO",    F, xdefmacro        ); /*  31 */
  2214. Xxldefine_prim("GENSYM",        S, xgensym        ); /*  32 */
  2215. Xxldefine_prim("MAKE-SYMBOL",    S, xmakesymbol        ); /*  33 */
  2216. Xxldefine_prim("INTERN",     S, xintern        ); /*  34 */
  2217. Xxldefine_prim("SYMBOL-NAME",    S, xsymname        ); /*  35 */
  2218. Xxldefine_prim("SYMBOL-VALUE",    S, xsymvalue        ); /*  36 */
  2219. Xxldefine_prim("SYMBOL-PLIST",    S, xsymplist        ); /*  37 */
  2220. Xxldefine_prim("GET",        S, xget    ); /*  38 */
  2221. Xxldefine_prim("PUTPROP",    S, xputprop); /*  39 */
  2222. Xxldefine_prim("REMPROP",    S, xremprop        ); /*  40 */
  2223. Xxldefine_prim("HASH",        S, xhash        ); /*  41 */
  2224. X    
  2225. X    /* array functions */
  2226. Xxldefine_prim("MAKE-ARRAY",    S, xmkarray        ); /*  42 */
  2227. Xxldefine_prim("AREF",        S, xaref        ); /*  43 */
  2228. X    
  2229. X    /* list functions */
  2230. Xxldefine_prim("CAR",        S, xcar            ); /*  44 */
  2231. Xxldefine_prim("CDR",        S, xcdr            ); /*  45 */
  2232. X    
  2233. Xxldefine_prim("CAAR",        S, xcaar        ); /*  46 */
  2234. Xxldefine_prim("CADR",        S, xcadr        ); /*  47 */
  2235. Xxldefine_prim("CDAR",        S, xcdar        ); /*  48 */
  2236. Xxldefine_prim("CDDR",        S, xcddr        ); /*  49 */
  2237. X    
  2238. Xxldefine_prim("CAAAR",        S, xcaaar        ); /*  50 */
  2239. Xxldefine_prim("CAADR",        S, xcaadr        ); /*  51 */
  2240. Xxldefine_prim("CADAR",        S, xcadar        ); /*  52 */
  2241. Xxldefine_prim("CADDR",        S, xcaddr        ); /*  53 */
  2242. Xxldefine_prim("CDAAR",        S, xcdaar        ); /*  54 */
  2243. Xxldefine_prim("CDADR",        S, xcdadr        ); /*  55 */
  2244. Xxldefine_prim("CDDAR",        S, xcddar        ); /*  56 */
  2245. Xxldefine_prim("CDDDR",        S, xcdddr        ); /*  57 */
  2246. X    
  2247. Xxldefine_prim("CAAAAR",     S, xcaaaar        ); /*  58 */
  2248. Xxldefine_prim("CAAADR",        S, xcaaadr        ); /*  59 */
  2249. Xxldefine_prim("CAADAR",        S, xcaadar        ); /*  60 */
  2250. Xxldefine_prim("CAADDR",        S, xcaaddr        ); /*  61 */
  2251. Xxldefine_prim("CADAAR",        S, xcadaar        ); /*  62 */
  2252. Xxldefine_prim("CADADR",        S, xcadadr        ); /*  63 */
  2253. Xxldefine_prim("CADDAR",        S, xcaddar        ); /*  64 */
  2254. Xxldefine_prim("CADDDR",        S, xcadddr        ); /*  65 */
  2255. Xxldefine_prim("CDAAAR",        S, xcdaaar        ); /*  66 */
  2256. Xxldefine_prim("CDAADR",        S, xcdaadr        ); /*  67 */
  2257. Xxldefine_prim("CDADAR",        S, xcdadar        ); /*  68 */
  2258. Xxldefine_prim("CDADDR",        S, xcdaddr        ); /*  69 */
  2259. Xxldefine_prim("CDDAAR",        S, xcddaar        ); /*  70 */
  2260. Xxldefine_prim("CDDADR",        S, xcddadr        ); /*  71 */
  2261. Xxldefine_prim("CDDDAR",        S, xcdddar        ); /*  72 */
  2262. Xxldefine_prim("CDDDDR",        S, xcddddr        ); /*  73 */
  2263. X    
  2264. Xxldefine_prim("CONS",        S, xcons        ); /*  74 */
  2265. Xxldefine_prim("LIST",        S, xlist        ); /*  75 */
  2266. Xxldefine_prim("APPEND",        S, xappend        ); /*  76 */
  2267. Xxldefine_prim("REVERSE",    S, xreverse        ); /*  77 */
  2268. Xxldefine_prim("LAST",        S, xlast        ); /*  78 */
  2269. Xxldefine_prim("NTH",        S, xnth            ); /*  79 */
  2270. Xxldefine_prim("NTHCDR",        S, xnthcdr        ); /*  80 */
  2271. Xxldefine_prim("MEMBER",        S, xmember        ); /*  81 */
  2272. Xxldefine_prim("ASSOC",        S, xassoc        ); /*  82 */
  2273. Xxldefine_prim("SUBST",         S, xsubst        ); /*  83 */
  2274. Xxldefine_prim("SUBLIS",        S, xsublis        ); /*  84 */
  2275. Xxldefine_prim("REMOVE",        S, xremove        ); /*  85 */
  2276. Xxldefine_prim("LENGTH",        S, xlength        ); /*  86 */
  2277. Xxldefine_prim("MAPC",        S, xmapc        ); /*  87 */
  2278. Xxldefine_prim("MAPCAR",        S, xmapcar        ); /*  88 */
  2279. Xxldefine_prim("MAPL",        S, xmapl        ); /*  89 */
  2280. Xxldefine_prim("MAPLIST",    S, xmaplist        ); /*  90 */
  2281. X    
  2282. X    /* destructive list functions */
  2283. Xxldefine_prim("RPLACA",        S, xrplca        ); /*  91 */
  2284. Xxldefine_prim("RPLACD",        S, xrplcd        ); /*  92 */
  2285. Xxldefine_prim("NCONC",        S, xnconc        ); /*  93 */
  2286. Xxldefine_prim("DELETE",        S, xdelete        ); /*  94 */
  2287. X    
  2288. X    /* predicate functions */
  2289. Xxldefine_prim("ATOM",        S, xatom        ); /*  95 */
  2290. Xxldefine_prim("SYMBOLP",    S, xsymbolp        ); /*  96 */
  2291. Xxldefine_prim("NUMBERP",    S, xnumberp        ); /*  97 */
  2292. Xxldefine_prim("BOUNDP",        S, xboundp         ); /*  98 */
  2293. Xxldefine_prim("NULL",        S, xnull        ); /*  99 */
  2294. Xxldefine_prim("LISTP",        S, xlistp        ); /* 100 */
  2295. Xxldefine_prim("CONSP",        S, xconsp        ); /* 101 */
  2296. Xxldefine_prim("MINUSP",        S, xminusp         ); /* 102 */
  2297. Xxldefine_prim("ZEROP",        S, xzerop        ); /* 103 */
  2298. Xxldefine_prim("PLUSP",        S, xplusp        ); /* 104 */
  2299. Xxldefine_prim("EVENP",        S, xevenp        ); /* 105 */
  2300. Xxldefine_prim("ODDP",        S, xoddp        ); /* 106 */
  2301. Xxldefine_prim("EQ",        S, xeq            ); /* 107 */
  2302. Xxldefine_prim("EQL",        S, xeql            ); /* 108 */
  2303. Xxldefine_prim("EQUAL",        S, xequal        ); /* 109 */
  2304. X    
  2305. X    /* special forms */
  2306. Xxldefine_prim("COND",        F, xcond        ); /* 110 */
  2307. Xxldefine_prim("CASE",        F, xcase        ); /* 111 */
  2308. Xxldefine_prim("AND",        F, xand            ); /* 112 */
  2309. Xxldefine_prim("OR",        F, xor            ); /* 113 */
  2310. Xxldefine_prim("LET",        F, xlet            ); /* 114 */
  2311. Xxldefine_prim("LET*",        F, xletstar        ); /* 115 */
  2312. Xxldefine_prim("IF",        F, xif            ); /* 116 */
  2313. Xxldefine_prim("PROG",        F, xprog        ); /* 117 */
  2314. Xxldefine_prim("PROG*",        F, xprogstar        ); /* 118 */
  2315. Xxldefine_prim("PROG1",        F, xprog1        ); /* 119 */
  2316. Xxldefine_prim("PROG2",        F, xprog2        ); /* 120 */
  2317. Xxldefine_prim("PROGN",        F, xprogn        ); /* 121 */
  2318. Xxldefine_prim("GO",        F, xgo            ); /* 122 */
  2319. Xxldefine_prim("RETURN",        F, xreturn          ); /* 123 */
  2320. Xxldefine_prim("DO",        F, xdo            ); /* 124 */
  2321. Xxldefine_prim("DO*",        F, xdostar          ); /* 125 */
  2322. Xxldefine_prim("DOLIST",        F, xdolist          ); /* 126 */
  2323. Xxldefine_prim("DOTIMES",    F, xdotimes        ); /* 127 */
  2324. Xxldefine_prim("CATCH",        F, xcatch        ); /* 128 */
  2325. Xxldefine_prim("THROW",        F, xthrow        ); /* 129 */
  2326. X    
  2327. X    /* debugging and error handling functions */
  2328. Xxldefine_prim("ERROR",        S, xerror        ); /* 130 */
  2329. Xxldefine_prim("CERROR",        S, xcerror          ); /* 131 */
  2330. Xxldefine_prim("BREAK",        S, xbreak        ); /* 132 */
  2331. Xxldefine_prim("CLEAN-UP",    S, xcleanup        ); /* 133 */
  2332. Xxldefine_prim("TOP-LEVEL",    S, xtoplevel        ); /* 134 */
  2333. Xxldefine_prim("CONTINUE",    S, xcontinue        ); /* 135 */
  2334. Xxldefine_prim("ERRSET",     F, xerrset          ); /* 136 */
  2335. Xxldefine_prim("BAKTRACE",       S, xbaktrace        ); /* 137 */
  2336. Xxldefine_prim("EVALHOOK",    S, xevalhook        ); /* 138 */
  2337. X    
  2338. X    /* arithmetic functions */
  2339. Xxldefine_prim("TRUNCATE",    S, xfix            ); /* 139 */
  2340. Xxldefine_prim("FLOAT",        S, xfloat        ); /* 140 */
  2341. Xxldefine_prim("+",        S, xadd            ); /* 141 */
  2342. Xxldefine_prim("-",        S, xsub            ); /* 142 */
  2343. Xxldefine_prim("*",        S, xmul            ); /* 143 */
  2344. Xxldefine_prim("/",        S, xdiv            ); /* 144 */
  2345. Xxldefine_prim("1+",        S, xadd1        ); /* 145 */
  2346. Xxldefine_prim("1-",        S, xsub1        ); /* 146 */
  2347. Xxldefine_prim("REM",        S, xrem            ); /* 147 */
  2348. Xxldefine_prim("MIN",        S, xmin            ); /* 148 */
  2349. Xxldefine_prim("MAX",        S, xmax            ); /* 149 */
  2350. Xxldefine_prim("ABS",        S, xabs            ); /* 150 */
  2351. Xxldefine_prim("SIN",        S, xsin            ); /* 151 */
  2352. Xxldefine_prim("COS",        S, xcos            ); /* 152 */
  2353. Xxldefine_prim("TAN",        S, xtan            ); /* 153 */
  2354. Xxldefine_prim("EXPT",        S, xexpt        ); /* 154 */
  2355. Xxldefine_prim("EXP",        S, xexp            ); /* 155 */
  2356. Xxldefine_prim("SQRT",        S, xsqrt        ); /* 156 */
  2357. Xxldefine_prim("RANDOM",        S, xrand        ); /* 157 */
  2358. X    
  2359. X    /* bitwise logical functions */
  2360. Xxldefine_prim("LOGAND",        S, xlogand          ); /* 158 */
  2361. Xxldefine_prim("LOGIOR",        S, xlogior          ); /* 159 */
  2362. Xxldefine_prim("LOGXOR",        S, xlogxor          ); /* 160 */
  2363. Xxldefine_prim("LOGNOT",        S, xlognot          ); /* 161 */
  2364. X    
  2365. X    /* numeric comparison functions */
  2366. Xxldefine_prim("<",        S, xlss            ); /* 162 */
  2367. Xxldefine_prim("<=",        S, xleq            ); /* 163 */
  2368. Xxldefine_prim("=",        S, xequ            ); /* 164 */
  2369. Xxldefine_prim("/=",        S, xneq            ); /* 165 */
  2370. Xxldefine_prim(">=",        S, xgeq            ); /* 166 */
  2371. Xxldefine_prim(">",        S, xgtr            ); /* 167 */
  2372. X    
  2373. X    /* string functions */
  2374. Xxldefine_prim("STRCAT",        S, xstrcat          ); /* 168 */
  2375. Xxldefine_prim("SUBSEQ",        S, xsubseq          ); /* 169 */
  2376. Xxldefine_prim("STRING",        S, xstring          ); /* 170 */
  2377. Xxldefine_prim("CHAR",        S, xchar        ); /* 171 */
  2378. X    
  2379. X    /* I/O functions */
  2380. Xxldefine_prim("READ",        S, xread        ); /* 172 */
  2381. Xxldefine_prim("PRINT",        S, xprint        ); /* 173 */
  2382. Xxldefine_prim("PRIN1",        S, xprin1        ); /* 174 */
  2383. Xxldefine_prim("PRINC",        S, xprinc        ); /* 175 */
  2384. Xxldefine_prim("TERPRI",        S, xterpri          ); /* 176 */
  2385. Xxldefine_prim("FLATSIZE",    S, xflatsize        ); /* 177 */
  2386. Xxldefine_prim("FLATC",        S, xflatc        ); /* 178 */
  2387. X    
  2388. X    /* file I/O functions */
  2389. Xxldefine_prim("OPEN",        S, xopen        ); /* 179 */
  2390. Xxldefine_prim("FORMAT",        S, xformat          ); /* 180 */
  2391. Xxldefine_prim("CLOSE",        S, xclose        ); /* 181 */
  2392. Xxldefine_prim("READ-CHAR",    S, xrdchar          ); /* 182 */
  2393. Xxldefine_prim("PEEK-CHAR",    S, xpkchar          ); /* 183 */
  2394. Xxldefine_prim("WRITE-CHAR",    S, xwrchar          ); /* 184 */
  2395. Xxldefine_prim("READ-LINE",    S, xreadline        ); /* 185 */
  2396. X    
  2397. X    /* system functions */
  2398. Xxldefine_prim("LOAD",        S, xload        ); /* 186 */
  2399. Xxldefine_prim("DRIBBLE",    S, xtranscript        ); /* 187 */
  2400. X    
  2401. X    /* functions specific to xldmem.c */
  2402. Xxldefine_prim("GC",        S, xgc            ); /* 188 */
  2403. Xxldefine_prim("EXPAND",        S, xexpand          ); /* 189 */
  2404. Xxldefine_prim("ALLOC",        S, xalloc        ); /* 190 */
  2405. Xxldefine_prim("ROOM",        S, xmem            ); /* 191 */
  2406. X#ifdef SAVERESTORE
  2407. Xxldefine_prim("SAVE",        S, xsave        ); /* 192 */
  2408. Xxldefine_prim("RESTORE",    S, xrestore        ); /* 193 */
  2409. X#else
  2410. Xxldefine_prim(NULL,        S, xnotimp        ); /* 192 */
  2411. Xxldefine_prim(NULL,        S, xnotimp        ); /* 193 */
  2412. X#endif
  2413. X    /* end of functions specific to xldmem.c */
  2414. X    
  2415. Xxldefine_prim("TYPE-OF",    S, xtype        ); /* 194 */
  2416. Xxldefine_prim("EXIT",        S, xexit        ); /* 195 */
  2417. Xxldefine_prim("PEEK",        S, xpeek        ); /* 196 */
  2418. Xxldefine_prim("POKE",        S, xpoke        ); /* 197 */
  2419. Xxldefine_prim("ADDRESS-OF",    S, xaddrs        ); /* 198 */
  2420. X    
  2421. X    /* new functions and special forms */
  2422. Xxldefine_prim("VECTOR",        S, xvector          ); /* 199 */
  2423. Xxldefine_prim("BLOCK",        F, xblock        ); /* 200 */
  2424. Xxldefine_prim("RETURN-FROM",    F, xrtnfrom        ); /* 201 */
  2425. Xxldefine_prim("TAGBODY",    F, xtagbody        ); /* 202 */
  2426. Xxldefine_prim("PSETQ",        F, xpsetq        ); /* 203 */
  2427. Xxldefine_prim("FLET",        F, xflet        ); /* 204 */
  2428. Xxldefine_prim("LABELS",        F, xlabels          ); /* 205 */
  2429. Xxldefine_prim("MACROLET",    F, xmacrolet        ); /* 206 */
  2430. Xxldefine_prim("UNWIND-PROTECT",    F, xunwindprotect    ); /* 207 */
  2431. Xxldefine_prim("PPRINT",        S, xpp            ); /* 208 */
  2432. Xxldefine_prim("STRING<",    S, xstrlss          ); /* 209 */
  2433. Xxldefine_prim("STRING<=",    S, xstrleq          ); /* 210 */
  2434. Xxldefine_prim("STRING=",    S, xstreql          ); /* 211 */
  2435. Xxldefine_prim("STRING/=",    S, xstrneq          ); /* 212 */
  2436. Xxldefine_prim("STRING>=",    S, xstrgeq          ); /* 213 */
  2437. Xxldefine_prim("STRING>",    S, xstrgtr          ); /* 214 */
  2438. Xxldefine_prim("STRING-LESSP",        S, xstrilss        ); /* 215 */
  2439. Xxldefine_prim("STRING-NOT-GREATERP",    S, xstrileq        ); /* 216 */
  2440. Xxldefine_prim("STRING-EQUAL",        S, xstrieql        ); /* 217 */
  2441. Xxldefine_prim("STRING-NOT-EQUAL",    S, xstrineq        ); /* 218 */
  2442. Xxldefine_prim("STRING-NOT-LESSP",    S, xstrigeq        ); /* 219 */
  2443. Xxldefine_prim("STRING-GREATERP",    S, xstrigtr        ); /* 220 */
  2444. Xxldefine_prim("INTEGERP",        S, xintegerp        ); /* 221 */
  2445. Xxldefine_prim("FLOATP",            S, xfloatp          ); /* 222 */
  2446. Xxldefine_prim("STRINGP",        S, xstringp        ); /* 223 */
  2447. Xxldefine_prim("ARRAYP",            S, xarrayp          ); /* 224 */
  2448. Xxldefine_prim("STREAMP",        S, xstreamp        ); /* 225 */
  2449. Xxldefine_prim("OBJECTP",        S, xobjectp        ); /* 226 */
  2450. Xxldefine_prim("STRING-UPCASE",        S, xupcase          ); /* 227 */
  2451. Xxldefine_prim("STRING-DOWNCASE",    S, xdowncase        ); /* 228 */
  2452. Xxldefine_prim("NSTRING-UPCASE",        S, xnupcase        ); /* 229 */
  2453. Xxldefine_prim("NSTRING-DOWNCASE",    S, xndowncase        ); /* 230 */
  2454. Xxldefine_prim("STRING-TRIM",        S, xtrim        ); /* 231 */
  2455. Xxldefine_prim("STRING-LEFT-TRIM",    S, xlefttrim        ); /* 232 */
  2456. Xxldefine_prim("STRING-RIGHT-TRIM",    S, xrighttrim        ); /* 233 */
  2457. Xxldefine_prim("WHEN",            F, xwhen        ); /* 234 */
  2458. Xxldefine_prim("UNLESS",            F, xunless          ); /* 235 */
  2459. Xxldefine_prim("LOOP",            F, xloop        ); /* 236 */
  2460. Xxldefine_prim("SYMBOL-FUNCTION",    S, xsymfunction        ); /* 237 */
  2461. Xxldefine_prim("FBOUNDP",        S, xfboundp        ); /* 238 */
  2462. Xxldefine_prim("SEND",            S, xsend        ); /* 239 */
  2463. Xxldefine_prim("SEND-SUPER",        S, xsendsuper        ); /* 240 */
  2464. Xxldefine_prim("PROGV",            F, xprogv        ); /* 241 */
  2465. Xxldefine_prim("CHARACTERP",        S, xcharp        ); /* 242 */
  2466. Xxldefine_prim("CHAR-INT",        S, xcharint        ); /* 243 */
  2467. Xxldefine_prim("INT-CHAR",        S, xintchar        ); /* 244 */
  2468. Xxldefine_prim("READ-BYTE",        S, xrdbyte          ); /* 245 */
  2469. Xxldefine_prim("WRITE-BYTE",        S, xwrbyte          ); /* 246 */
  2470. Xxldefine_prim("MAKE-STRING-INPUT-STREAM",     S, xmkstrinput        ); /* 247 */
  2471. Xxldefine_prim("MAKE-STRING-OUTPUT-STREAM",    S, xmkstroutput        ); /* 248 */
  2472. Xxldefine_prim("GET-OUTPUT-STREAM-STRING",    S, xgetstroutput    ); /* 249 */
  2473. Xxldefine_prim("GET-OUTPUT-STREAM-LIST",    S, xgetlstoutput    ); /* 250 */
  2474. Xxldefine_prim("GCD",            S, xgcd            ); /* 251 */
  2475. Xxldefine_prim("GET-LAMBDA-EXPRESSION",     S, xgetlambda        ); /* 252 */
  2476. Xxldefine_prim("MACROEXPAND",        S, xmacroexpand        ); /* 253 */
  2477. Xxldefine_prim("MACROEXPAND-1",        S, x1macroexpand    ); /* 254 */
  2478. Xxldefine_prim("CHAR<",            S, xchrlss          ); /* 255 */
  2479. Xxldefine_prim("CHAR<=",            S, xchrleq          ); /* 256 */
  2480. Xxldefine_prim("CHAR=",            S, xchreql          ); /* 257 */
  2481. Xxldefine_prim("CHAR/=",            S, xchrneq          ); /* 258 */
  2482. Xxldefine_prim("CHAR>=",            S, xchrgeq          ); /* 259 */
  2483. Xxldefine_prim("CHAR>",            S, xchrgtr          ); /* 260 */
  2484. Xxldefine_prim("CHAR-LESSP",        S, xchrilss        ); /* 261 */
  2485. Xxldefine_prim("CHAR-NOT-GREATERP",    S, xchrileq        ); /* 262 */
  2486. Xxldefine_prim("CHAR-EQUAL",        S, xchrieql        ); /* 263 */
  2487. Xxldefine_prim("CHAR-NOT-EQUAL",        S, xchrineq        ); /* 264 */
  2488. Xxldefine_prim("CHAR-NOT-LESSP",        S, xchrigeq        ); /* 265 */
  2489. Xxldefine_prim("CHAR-GREATERP",        S, xchrigtr        ); /* 266 */
  2490. Xxldefine_prim("UPPER-CASE-P",        S, xuppercasep        ); /* 267 */
  2491. Xxldefine_prim("LOWER-CASE-P",        S, xlowercasep        ); /* 268 */
  2492. Xxldefine_prim("BOTH-CASE-P",        S, xbothcasep        ); /* 269 */
  2493. Xxldefine_prim("DIGIT-CHAR-P",        S, xdigitp        ); /* 270 */
  2494. Xxldefine_prim("ALPHANUMERICP",        S, xalphanumericp    ); /* 271 */
  2495. Xxldefine_prim("CHAR-UPCASE",        S, xchupcase        ); /* 272 */
  2496. Xxldefine_prim("CHAR-DOWNCASE",        S, xchdowncase        ); /* 273 */
  2497. Xxldefine_prim("DIGIT-CHAR",        S, xdigitchar        ); /* 274 */
  2498. Xxldefine_prim("CHAR-CODE",        S, xcharcode        ); /* 275 */
  2499. Xxldefine_prim("CODE-CHAR",        S, xcodechar        ); /* 276 */
  2500. Xxldefine_prim("ENDP",            S, xendp        ); /* 277 */
  2501. Xxldefine_prim("REMOVE-IF",        S, xremif        ); /* 278 */
  2502. Xxldefine_prim("REMOVE-IF-NOT",        S, xremifnot        ); /* 279 */
  2503. Xxldefine_prim("DELETE-IF",        S, xdelif        ); /* 280 */
  2504. Xxldefine_prim("DELETE-IF-NOT",        S, xdelifnot        ); /* 281 */
  2505. Xxldefine_prim("TRACE",            F, xtrace        ); /* 282 */
  2506. Xxldefine_prim("UNTRACE",        F, xuntrace        ); /* 283 */
  2507. Xxldefine_prim("SORT",            S, xsort        ); /* 284 */
  2508. Xxldefine_prim("DEFSTRUCT",        F, xdefstruct        ); /* 285 */
  2509. Xxldefine_prim("%STRUCT-TYPE-P",        S, xstrtypep        ); /* 286 */
  2510. Xxldefine_prim("%MAKE-STRUCT",        S, xmkstruct        ); /* 287 */
  2511. Xxldefine_prim("%COPY-STRUCT",        S, xcpystruct        ); /* 288 */
  2512. Xxldefine_prim("%STRUCT-REF",        S, xstrref        ); /* 289 */
  2513. Xxldefine_prim("%STRUCT-SET",        S, xstrset        ); /* 290 */
  2514. Xxldefine_prim("ASIN",            S, xasin        ); /* 291 */
  2515. Xxldefine_prim("ACOS",            S, xacos        ); /* 292 */
  2516. Xxldefine_prim("ATAN",            S, xatan        ); /* 293 */
  2517. X    
  2518. X    /* extra table entries */
  2519. Xxldefine_prim("SYSTEM",            S, Prim_SYSTEM        ); /* 294 NPM */
  2520. Xxldefine_prim("POPEN",            S, Prim_POPEN        ); /* 295 NPM */
  2521. Xxldefine_prim("PCLOSE",            S, Prim_PCLOSE        ); /* 296 NPM */
  2522. Xxldefine_prim("FSCANF-FIXNUM",        S, Prim_FSCANF_FIXNUM    ); /* 297 NPM */
  2523. Xxldefine_prim("FSCANF-STRING",        S, Prim_FSCANF_STRING    ); /* 298 NPM */
  2524. Xxldefine_prim("FSCANF-FLONUM",        S, Prim_FSCANF_FLONUM    ); /* 299 NPM */
  2525. Xxldefine_prim("COPY-ARRAY",        S, Prim_COPY_ARRAY    ); /* 300 NPM */
  2526. Xxldefine_prim("ARRAY-INSERT-POS",    S, Prim_ARRAY_INSERT_POS); /* 301 NPM */
  2527. Xxldefine_prim("ARRAY-DELETE-POS",    S, Prim_ARRAY_DELETE_POS); /* 302 NPM */
  2528. X    
  2529. X    /* include system dependant function pointers */
  2530. X#include "osptrs.h"
  2531. X    
  2532. X/* Include hybrid-class funtab entries: */  /* JSP a la Voodoo */
  2533. X#define MODULE_XLFTAB_C_FUNTAB_S
  2534. X#include "../../xmodules.h"
  2535. X#undef MODULE_XLFTAB_C_FUNTAB_S
  2536. X
  2537. X/* Include hybrid-class funtab entries: */  /* JSP a la Voodoo */
  2538. X#define MODULE_XLFTAB_C_FUNTAB_F
  2539. X#include "../../xmodules.h"
  2540. X#undef MODULE_XLFTAB_C_FUNTAB_F
  2541. X
  2542. X}
  2543. END_OF_FILE
  2544. if test 22885 -ne `wc -c <'src/xlisp/xcore/c/xlftab.c'`; then
  2545.     echo shar: \"'src/xlisp/xcore/c/xlftab.c'\" unpacked with wrong size!
  2546. fi
  2547. # end of 'src/xlisp/xcore/c/xlftab.c'
  2548. fi
  2549. echo shar: End of archive 10 \(of 16\).
  2550. cp /dev/null ark10isdone
  2551. MISSING=""
  2552. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  2553.     if test ! -f ark${I}isdone ; then
  2554.     MISSING="${MISSING} ${I}"
  2555.     fi
  2556. done
  2557. if test "${MISSING}" = "" ; then
  2558.     echo You have unpacked all 16 archives.
  2559.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2560. else
  2561.     echo You still need to unpack the following archives:
  2562.     echo "        " ${MISSING}
  2563. fi
  2564. ##  End of shell archive.
  2565. exit 0
  2566.